Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

Time of day = Script Disables? [UNANSWERED]

Asked by 8 years ago

So. I have a script in which when the time reaches 21:00:00, or 9pm, the scripts to open a gate stop working and then when the time reached 6:00:00 it re-activates.... BUT, it doesn't work, could someone help?

Current Code:

if game.Lighting.TimeOfDay == "21:00:00" then
    game.workspace.Security.Rear.Open.R.Enabled = false
    game.workspace.Security.Rear.Open.L.Enabled = false
    game.workspace.Security.Front.Open.R.Enabled = false
    game.workspace.Security.Front.Open.L.Enabled = false

elseif game.Lighting.TimeOfDay == "06:00:00" then
    game.workspace.Security.Rear.Open.R.Enabled = true
    game.workspace.Security.Rear.Open.L.Enabled = true
    game.workspace.Security.Front.Open.R.Enabled = true
    game.workspace.Security.Front.Open.L.Enabled = true
end

Layout: http://prntscr.com/904eu9

2 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

First off, your if statements are wrong. elseif does not require its own end.

if condition then
    --code
elseif condition2 then
    --code
end

Second, Lighting needs to be capital.

game.Lighting

Third, when doing comparisons, you need to use two equal signs:

if a == b then

Fourth, TimeOfDay is actually a string, so check it like this:

if game.Lighting.TimeOfDay == "21:00:00" then
Ad
Log in to vote
-1
Answered by 8 years ago

while true do wait() if game.lighting.TimeOfDay == 21:00:00 then game.workspace.Security.Rear.Open.R.Enabled = false game.workspace.Security.Rear.Open.L.Enabled = false game.workspace.Security.Front.Open.R.Enabled = false game.workspace.Security.Front.Open.L.Enabled = false

elseif game.lighting.TimeOfDay == 06:00:00 then
    game.workspace.Security.Rear.Open.R.Enabled = true
    game.workspace.Security.Rear.Open.L.Enabled = true
    game.workspace.Security.Front.Open.R.Enabled = true
    game.workspace.Security.Front.Open.L.Enabled = true
end

end

Answer this question