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

TimeOfDay "=" sign not working?

Asked by 9 years ago

For some reason the first equal sign shows up as an error in the script. The script isn't working, either. What am I doing wrong?

if game.Lighting.TimeOfDay = "18:00:00" then
    script.Parent.BrickColor = BrickColor.new("Really yellow") elseif
    game.Lighting.TimeOfDay = "6:00:00" then
    script.Parent.BrickColor = BrickColor.new("Really black")
end

2 answers

Log in to vote
1
Answered by 9 years ago

Same thing as funyun said but:

game:GetService("Lighting").Changed:connect(function() --Use Changed instead of while loops to make less lag
    if game.Lighting.TimeOfDay == "18:00:00" then
            script.Parent.BrickColor = BrickColor.new("New yeller") --Really yellow is not a color!
    elseif game.Lighting.TimeOfDay == "6:00:00" then
            script.Parent.BrickColor = BrickColor.new("Really black")
    end
end)

Hope it helps!

Ad
Log in to vote
1
Answered by
funyun 958 Moderation Voter
9 years ago

In conditionals, if you want to check if two things are equal, you use ==, not =. When you're setting values, like changing a part's BrickColor, you use =.

You will also need to constantly check the time. When the game runs, the script will only check the time once, and then it will do nothing else. Let's make a loop to solve this.

while wait() do --Every time this loop runs, it will check the time, and if the time is 6 AM or 6 PM, it will do the stuff.
    if game.Lighting.TimeOfDay == "18:00:00" then
            script.Parent.BrickColor = BrickColor.new("Really yellow") elseif
            game.Lighting.TimeOfDay == "6:00:00" then
            script.Parent.BrickColor = BrickColor.new("Really black")
    end
end
0
Thanks, the error went away, but the brick still isnt changing color when it needs to. I made TimeOfDay == "18:00:00", as well as "6:00:00". branflakes1099 30 — 9y
0
I edited my answer funyun 958 — 9y
1
I know why! Really yellow isn't a roblox brick color, use "New Yeller" or "Bright yellow" (Yeah I know, roblox has weird colors) lucas4114 607 — 9y

Answer this question