Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

TimeOfDay "=" sign not working?

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

✓ Accepted answer

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!

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

3 comments

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".

0

I edited my answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.