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

TimeOfDay Code and string errors unable to resolve. Help?

function onTouched()
 game.Lighting.TimeOfDay= "5:00:00"
   

while game.Lighting.TimeOfDay<tonumber("6:00:00") do   
	repeat
	game.Lighting.TimeOfDay = game.Lighting.TimeOfDay + "0:01:00" 
	wait(.1)
	until game.Lighting.TimeOfDay > "6:00:00"
end
end

script.Parent.Touched:connect(onTouched)  

new to scripting ! current error : attempt to compare string with nil

I've fixed several errors such as above but script doesn't run, I know the issue with it. Is there anyway I can get around this? Do I need to take a different approach?

Not sure where to start D:

2 comments

0

could you explain a bit more? if you want to make a simple time changing script, it would be:                                                                                                                                       while wait(0.2) do game.Lighting:SetMinutesAfterMidnight(game.Lighting:GetMinutesAfterMidnight()+1) end

0

when a player walks on a block this script above is triggered, causing timeofday to go from 5:00:00 to 6:00:00 in a few seconds. Single player game

1 answer

✓ Accepted answer

Trying to compare TimeOfDay might be confusing it, given it has colons. Try instead to use Lighting.Clocktime. Also, you have two loops (a while and repeat) doing the same thing, so you can just remove one of them.

local function onTouched()
	game.Lighting.ClockTime = 5

	while game.Lighting.ClockTime < 6 do
		game.Lighting.ClockTime = game.Lighting.ClockTime + 0.01
		wait(0.1)
	end
end

script.Parent.Touched:connect(onTouched)

1 comment

0

Thank you

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