My Roblox Script doesn't change the model based on time (Roblox) - roblox

I'm working on an automatic Street Light that is supposed to change based on the time. Here is the code:
--------------------------------------------
-----------Street Light Script!-------------
-----------Made by multiplemark-------------
--------------------------------------------
local ControlledByGameTime = true -- Setting to true makes it so that the lights
activate only during the selected time.
local TurnLightsOnAt = 20 * 60 -- Turns lights on at 8 P.M. by default.
local TurnLightsOffAt = 8 * 60 -- Turns lights off at 8 A.M. by default.
local Lights = script.Parent.PointLight.Enabled
local LightBlock = script.Parent
if ControlledByGameTime == true then
while true do
local CurrentTime = game.Lighting:GetMinutesAfterMidnight()
if CurrentTime >= TurnLightsOffAt then
Lights = false
LightBlock.Material = "SmoothPlastic"
LightBlock.Brick = 163,162,165
end
if CurrentTime >= TurnLightsOnAt then
Lights = true
LightBlock.Material = "Neon"
LightBlock.Brick = 255,255,0
end
end
else
Lights = true
LightBlock.Material = "Neon"
LightBlock.Color = 255,255,0
end
What it is supposed to do is check for the time, and if it meets the requirements defined, change the material and color of a model, and also enabling/disabling PointLight.

I think the issue is your if statements. You're evaluating if it's after 8 pm after you evaluate if it's 8 am. Since 8 pm (or 20 in 24-hour format) comes after 8 am (or 8 24-hour format), if a value if greater than 8 pm, it's also greater than 8 am.
What you could do is just have an equals statement instead of a greater than. So something like:
if (time==TURNOFFLIGHTS)
turnofflights ();
else if (time==TURNONLIGHTS)
turnonlights ();
That way, it only turns off the lights at the specific moment that night begins and only turns them on the moment day begins.

Related

When I mine a rock in my game (Click it 10 times) it mines and gives 100 coins. However if someone else does it it gives it to me? Can anyone h3lp?

So when I click it 10 times it mines however it only give coins to me when someone else mines it. I have no clue really what to do so i need help. Ok so here is the script:
game.Players.PlayerAdded:Connect(function(player)
script.Parent:Clone()
local money = player:WaitForChild("leaderstats").Money
script.Parent.ClickDetector.MouseClick:Connect(function()
local billboard = script.Parent.BillboardGui
print(health)
health = health - 1
billboard.Enabled = true
billboard.TextLabel.Text = health
if health == 0 then
local clickdetector = script.Parent.ClickDetector
billboard.Enabled = false
money.Value = money.Value + 100
script.Parent.ClickDetector.Parent = nil
script.Parent.Union.Transparency = 1
script.Parent.Union.CanCollide = false
wait(5)
clickdetector.Parent = script.Parent
script.Parent.Union.Transparency = 0
script.Parent.Union.CanCollide = true
health = 10
end
end)
end)
The problem is that you need to make sure the player variable matches the player that clicked it.
script.Parent.ClickDetector.MouseClick:Connect(function()
should be:
script.Parent.ClickDetector.MouseClick:Connect(function(clicker)
and use an if statement:
if clicker == player then
--code that gives points
end
Also when you clone the parent it clones the script so that may cause bugs.

ROBLOX - How would I move the player 8 studs, for 20 miliseconds smoothly (so tweening), in the direction the player is facing?

How would I move the player 8 studs, for 20 miliseconds smoothly (so tweening), in the direction the player is facing?
script.Parent.Activated:Connect(function()
--[This is because this is a localscript in a tool]
end)
local isGliding = false;
script.Parent.Activated:Connect(function()
isGliding = not isGliding;
local char = script.Parent.Parent; --The tool gets inside of the char when activated
local humanoidRootPart = char:WaitForChild("HumanoidRootPart");
coroutine.wrap(function()
while true do
humanoidRootPart.Positon += humanoidRootPart.LookVector * 8;
wait(0.3)
if isGliding == false then
break;
end
end
end)()
end)
Something like that probably. This should be in a ServerScript under the tool.

Anylogic Variable Not Updating

I an using a discrete event simulator in AnyLogic. I am having an issue with some code which updates a variable in my simulation. I store both the datetime at which the agent leaves the source block and the datetime at which it enters the sink block. I am trying to record the number of "rule breaks" for all agents. The rule break is defined below (two ways to break):
1) If the agent is received before a certain time (called SDC) and the agent is not completed by 5pm the same day, then the agent has broken the rule
2) If the agent is not completed by the next day at a certain time (called NDC), then the agent has broken the rule
I record a zero or a one for each agent if they break either rule in the variable called RuleBreak. However, in my simulation runs, the variable does not update at all. I hope I am just missing something small. Would appreciate any help! (code below)
Calendar received = Calendar.getInstance();
received.setTime(ReceivedDate);
Calendar completion = Calendar.getInstance();
completion.setTime(Completion);
Calendar SD_at_5 = Calendar.getInstance();
SD_at_5.setTime(ReceivedDate);
SD_at_5.set(Calendar.HOUR_OF_DAY,17);
SD_at_5.set(Calendar.MINUTE, 0);
SD_at_5.set(Calendar.SECOND, 0);
Calendar Tomorrow_at_NDC = Calendar.getInstance();
Tomorrow_at_NDC.setTime(ReceivedDate);
if(Tomorrow_at_NDC.get(Calendar.DAY_OF_WEEK) == 6)
Tomorrow_at_NDC.add(Calendar.DATE, 3);
else
Tomorrow_at_NDC.add(Calendar.DATE, 1);
Tomorrow_at_NDC.add(Calendar.DATE, 1);
Tomorrow_at_NDC.set(Calendar.HOUR_OF_DAY,NDC);
Tomorrow_at_NDC.set(Calendar.MINUTE, 0);
Tomorrow_at_NDC.set(Calendar.SECOND, 0);
int Either_rule_break = 0;
double time_diff_SDC = differenceInCalendarUnits(TimeUnits.SECOND,completion.getTime(),SD_at_5.getTime());
double time_diff_NDC = differenceInCalendarUnits(TimeUnits.SECOND,completion.getTime(),Tomorrow_at_NDC.getTime());
if((received.get(Calendar.HOUR_OF_DAY) < SDC) && (time_diff_SDC <= 0))
Either_rule_break = Either_rule_break + 1;
else
Either_rule_break = Either_rule_break + 0;
if((received.get(Calendar.HOUR_OF_DAY) >= SDC) && (time_diff_NDC <= 0))
Either_rule_break = Either_rule_break + 1;
else
Either_rule_break = Either_rule_break + 0;
if((Either_rule_break >= 1))
RuleBreak = RuleBreak + 1;
else
RuleBreak = RuleBreak + 0;
You haven't really explained where this code is used and what it receives. I assume the code is in a function, called in the sink's on-enter action, where ReceivedDate and Completion are Date instances stored per agent (source exit time and sink entry time, as dates, captured via AnyLogic's date() function).
And looks like your SDC hour-of-day is stored in SDC and your NDC hour-of-day in NDC (with RuleBreak being a variable in Main or similar storing the total number of rule-breaks).
Your calculations look OK except that the Tomorrow_at_NDC Calendar calculation seems wrong: you add 1 day twice (if not Saturday) or 3 days plus 1 day (if Saturday; in a Java Calendar, day-of-week 1 is Monday).
(Your Java is also very 'inefficient' with unnecessary extra local variables and performing logic when you don't need to; e.g., no point doing all the calendar preparation and check for your type 1 rule-break if the receive time is after the SDC hour.)
But are you sure there are any rule-breaks; how have you set up your model to ensure that there are (to test it)? Plus is RuleBreak definitely a variable outside of the agents that flow through your DES (i.e., in Main or similar)? Plus are Completion and ReceivedDate definitely stored per agent so, for example, if your function was called checkForRuleBreaks you would be doing something like the below in your sink on-exit action:
agent.Completion = date(); // Agent received date set earlier in Source action
checkForRuleBreaks(agent.ReceivedDate, agent.Completion);
(In fact, you don't need to store the completion date in the agent at all since that will always be the current sim-date inside your function and so you can just calculate it there.)

NSDate timeIntervalSinceDate calculates incorrectly by 60 minutes

Trying to figure out why the following code results in 90,000 which is exactly 1 hour over a day. The created dates are both set to noon of consecutive days so the answer should be 86,400 (24*60*60).
let currentCalendar = NSCalendar.currentCalendar();
let components1 = NSDateComponents()
components1.year = 2015
components1.month = 11
components1.day = 1
components1.hour = 12
components1.minute = 0
components1.second = 0
let myDate1 = currentCalendar.dateFromComponents(components1)!
let components2 = NSDateComponents()
components2.year = 2015
components2.month = 10
components2.day = 31
components2.hour = 12
components2.minute = 0
components2.second = 0
let myDate2 = currentCalendar.dateFromComponents(components2)!
let difference = myDate1.timeIntervalSinceDate(myDate2)
Running swift 2 (Xcode 7.0)
Daylight savings time ends on Nov 1, 2015. The 25-hour difference is correct. There will also be a 23-hour day in the spring when DST begins.
This is why, if you want to be sure to get the same clock time on another date, you can’t just add or subtract multiples of 24 hours.
This only goes for places that observe DST, which is probably why some commenters on the original question are seeing a 24-hour difference in their local time zone.

DHTMLX Scheduler - Calendar view - set focus to config.mark_now

When loading the calendar, I have divided the hours into intervals of 30 mins each.
This is my initial configuration.
scheduler.locale.labels.unit_tab = "Resources";
scheduler.config.hour_date = "%h:%i %A";
scheduler.config.hour_size_px = 88;
scheduler.config.mark_now = true;
scheduler.locale.labels.section_custom = "Assigned to";
scheduler.config.separate_short_events = true;
scheduler.config.drag_move = false;
scheduler.config.drag_resize = false;
Due to the 30 mins, my calendar has a scroll bar. The default calendar shows only about 6.5 hrs. So if the current time is 3 PM, the mark_now line is off the view. How do I set focus to the current time and have the current time or mark_now be in the horizontal center of the display?
I am learning dhtmlx and may not be able to answer all queries so would appreciate any guidance. Thanks in advance!
You can add something like next
scheduler.config.scroll_hour = (new Date).getHours();
It will configure scheduler to scroll day or week view to the current hour.