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

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

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

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