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

Why won't this turn on/off script turn ON?

-- Turning On and off script

		Light = script.Parent.PointLight
while wait() do
if game.Lighting.TimeOfDay == "19:00:00" then
	Light.Enabled = true
	script.Parent.Material = "Neon"
else if game.Lighting.TimeOfDay == "06:00:00" then
	Light.Enabled = false
	script.Parent.Material = "DiamondPlate"
	
	end	
end
end

Is it just server lag or does the first if statement not work?

So I have this loop running in about 17 lamps in my game. All functioning in a regular script. Most simple job ever. Turn on at This and That time.

It turns off at 6:00:00, but it won't turn on at 19:00:00 UNIX time. Would a function work better in this situation?

Help?

1 answer

✓ Accepted answer

Try using that script

lightPart = game.Workspace.LightPart
minutesAfterMidnight = 0
 
while true do
	minutesAfterMidnight = minutesAfterMidnight + 10 -- Day/Night Cycle
	game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
	wait(1)
 
	if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then		-- checks for 6AM
		lightPart.Material = Enum.Material.Plastic
		lightPart.PointLight.Enabled = false
	end
	if game.Lighting:GetMinutesAfterMidnight() == 19 * 60 then		-- checks for 7PM
		lightPart.Material = Enum.Material.Neon
		lightPart.PointLight.Enabled = true
	end
end

2 comments

0

I was right about the script moving too fast, but this script is a bit cleaner in my opinion. Thanks! :)

0

No problem ;)

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