Loop doesn't work if task.wait is before it

no clue why it isn’t working

Probably something else in the code, i dont know

Okay, you should try and file a #bug-reports, maybe it’s a bug?

Okay so, from what we know the code works in isolation, but not inside your module when delayed. So what other code is running whilst the loop is being delayed?
I think this is called a race condition and might be a great example of it.
Is something else causing it to lose scope, or is it inside another thread or script which is being cancelled or destroyed?

I’ve read over the thread and the replies, but I feel like we need to see more of the code to know what’s going wrong, such as where the function this is within is called, what other functions may be currently running, and if there’s a possibility that you’re calling another function that does the opposite (adding to diffuse/specular) as that could be why it’s not functioning as intended.

Have you tried this yet?

task.spawn(function()
    game.Workspace.GlobalSounds.powerDown:Play()
	task.delay(1,function()
		for count = 1, 10 do
		   game.Lighting.EnvironmentDiffuseScale -= 0.156
		   game.Lighting.EnvironmentSpecularScale -= 0.156
	       task.wait(0.1)
	    end
    end)
end)

psuedo code

task.spawn(FUNC)
print(HI)<— this’ll run,
task.wait(1)
print(HI2) <---- this won’t run

End)

Same happens with task.delay, however the entire thread doesnt work.
There is absolutely no script that adds back the lighting. It just isn’t running

1 Like