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

TimeOfDay Code and string errors unable to resolve. Help?

Asked by 5 years ago
Edited 5 years ago
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:

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 cruizer_snowman 117 — 5y
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 mer5000 2 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
0
Thank you mer5000 2 — 5y
Ad

Answer this question