game.Workspace.GlobalSounds.powerDown:Play()
task.spawn(function()
task.wait(1)
for count = 1, 10 do
game.Lighting.EnvironmentDiffuseScale -= 0.17
game.Lighting.EnvironmentSpecularScale -= 0.17
task.wait(0.1)
end
end)
task.spawn(function()
local now1 = tick()
task.wait(1)
print(tick()-now1)
for i=1, 3 do
local now2 = tick()
task.wait(1)
print(tick()-now2)
end
end)
Like this? Nothing’s in the output and it behaves as it did before.
Hi, I tested your script exactly how you sent it and on my end it works, and just to clarify, is your issue about the sound not playing, the lightning not changing, or the thread not running entirely?
task.spawn(function()
task.wait(1)
for count = 1, 10 do
generate.BrightnessChange(0.08)
game.Lighting.EnvironmentDiffuseScale -= 0.17
game.Lighting.EnvironmentSpecularScale -= 0.17
task.wait(0.1)
end
end)
If you have the code like this above, the LOOP doesn’t run. The sound plays, but not the loop.
However, if it’s like this
task.wait(1)
task.spawn(function()
for count = 1, 10 do
generate.BrightnessChange(0.08)
game.Lighting.EnvironmentDiffuseScale -= 0.17
game.Lighting.EnvironmentSpecularScale -= 0.17
task.wait(0.1)
end
end)
It works, but it stops the entire thread since… It’s not in a corountine anymore. Which is undesired, I want it to not stop the entire thread. But if i put the task.wait() inside of the spawn, it the loop doesn’t run.
function generate.generateRoom()
local randomRoom = generate.getRandom()
local newRoom = randomRoom:Clone()
local newDoor = generate.NewDoor(newRoom)
generate.RoomNum += 1
newRoom:PivotTo(generate.prevRoom.Exit.CFrame)
generate.prevRoom = newRoom
for i, v in pairs(newRoom:GetChildren()) do
if v.Name == "Lights" then
v.Shine.Parent = game.Workspace.GeneratedLights
end
end
if not generate.LightSystem and generate.RoomNum == 3 then
game.Workspace.GlobalSounds.powerDown:Play()
task.spawn(function()
task.wait(1)
for count = 1, 10 do
game.Lighting.EnvironmentDiffuseScale -= 0.17
game.Lighting.EnvironmentSpecularScale -= 0.17
task.wait(0.1)
end
end)
elseif generate.RoomNum > 3 and not generate.LightSystem then
generate.BrightnessChange(0)
elseif generate.LightSystem and generate.RoomNum >= 30 then
generate.BrightnessChange(0.007)
end
newRoom.Parent = workspace.GeneratedRooms
script.Parent.NewRoomGenerated:Fire()
end
The problem you’re facing might be related to something else in your script. I’ve reviewed your code, and it should work as intended. There might be another issue causing your problem, such as:
game.Workspace.GlobalSounds.powerDown is not a sound or does not exist.
There’s another script changing game.Lighting.EnvironmentDiffuseScale or game.Lighting.EnvironmentSpecularScale at the same time.
The changes in game.Lighting.EnvironmentDiffuseScale or game.Lighting.EnvironmentSpecularScale are not visible due to other game settings or because the changes are too small to notice.
To check if your loop is actually running, you could add print statements within the loop, such as:
task.spawn(function()
game.Workspace.GlobalSounds.powerDown:Play()
task.wait(1)
for count = 1, 10 do
game.Lighting.EnvironmentDiffuseScale -= 0.156
game.Lighting.EnvironmentSpecularScale -= 0.156
print("In first loop, count = "..count) -- add this
task.wait(0.1)
end
end)
game.Workspace.GlobalSounds.powerDown:Play()
task.wait(1)
task.spawn(function()
for count = 1, 10 do
game.Lighting.EnvironmentDiffuseScale -= 0.156
game.Lighting.EnvironmentSpecularScale -= 0.156
print("In second loop, count = "..count) -- add this
task.wait(0.1)
end
end)
Already tried adding print statements. Loop isn’t running at all. However, there is another function changing the enviromentspecularscale at the same time. It’s subtracting its value, so that may be the issue. There aren’t any errors, so if powerDown didn’t exist, it would say so. Plus I know it exists.
That’s peculiar, honestly can’t see why it wouldn’t work because testing shows the loop to run perfectly fine. Have you tried using task.delay? It’ll achieve the same thing, and in the mean-time you can figure out what’s causing the loop to not run.