I have this loop, however if the task.wait is like this… The loop won’t play at all.
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
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
task.wait(0.1)
end
end)
But, if it’s like this the loop will play but will stall the rest of the script. I want to know why it doesn’t play if the task.wait() is placed inside of the task.spawn.
I think I’m having a similar problem, I’m spawning a loop with task.spawn() and I’m trying to wait with task.wait() in it but it doesn’t wait and it just goes too fast, it doesn’t error tho
Why don’t you try Tweening the attribute instead?
Like this
local Lighting = game:GetService("Lighting")
local TweenService = game:GetService("TweenService")
local Tween = TweenService:Create(Lighting,TweenInfo.new(1),{EnvironmentDiffuseScale = 0})
Tween:Play()
I’m not OP, I also can’t use Tweens because I need something else, something that isn’t achievable with Tweens
(OP’s problem may be solved with Tweens tho)
Basically I’m trying to make something that goes exponentially (which as far as I know isn’t achievable with Tweens) but I’m also having the same problem as OP (I think)
It doesn’t work with wait() either
(If you want to go ahead do it in DMs)
I wrote this, it increments 2 variables each second using different loops,
I tested it and it worked
local Number = 0
local Number2 = 0
local Increment = 1
local Count = false
local function IncrementNumbers()
task.spawn(function()
while Count do
task.wait(Increment)
Number += 1
print(Number.." AA ")
end
end)
task.spawn(function()
while Count do
task.wait(Increment)
Number2 += 1
print(Number2.." AA ")
end
end)
end
Count = true
IncrementNumbers()
It doesn’t work for me, my code works like this;
Calls function
After it creates a loop with task.spawn() which doesn’t wait
After it creates another loop with the same method, and doesn’t wait either