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

How do I run code alongside a while loop without looping it?

Asked by 4 years ago
Edited 4 years ago

I am trying to make a script that changes the ambient music depending on the current ClockTime but the variable T is in a while loop, I tried putting the if and elseif statement in the while true loop but it restarted the song about every 0.5 seconds (I think the reason why it was taking about 0.5 seconds to restart the song was because wait(0.5) was the first line of code in the while loop), I also tried putting the if and elseif statements behind the while loop, I knew that it wasn't going to work.

Code:

L = game:GetService("Lighting")

while true do 
    wait(0.5)
    T = L:GetMinutesAfterMidnight()
    L:SetMinutesAfterMidnight(T + 1)
    if T == 390 then -- Morning
        workspace.Ambient1Night:Stop()
        workspace.Ambient1Day:Play()
    elseif T == 1140 then -- Night time, before midnight
        workspace.Ambient1Day:Stop()
        workspace.Ambient1Night:Play()
    end
end


1 answer

Log in to vote
0
Answered by 3 years ago

lol use spawn(function() end)

Ad

Answer this question