hi, the title says it, i think my for loop is broken when i think it shouldent take a look:
local status = game.ReplicatedStorage.Status
local cooldown = 5 -- 240
local currentDay = game.ReplicatedStorage.Day
local mSpeed = game.ReplicatedStorage.MonsterSpeed
local isSleeping = game.ReplicatedStorage.isSleeping
local function timer()
for i = cooldown, 1, -1 do
print(cooldown)
print(status.Value)
if cooldown == 0 then
status.Value = "Night"
end
task.wait(1)
end
end
spawn(timer)
and yes i have read the documentation and i still think this should work
if you know why its broken pls let me know.
I dont really understand what u mean with âcooldown can never get to 1 because the value is set to oneâ as to earlier in the script it is set to 5 but it also can be my braindead brain
Your code doesnât really make sense. Your cooldown variable is 5 and your for loop has an increment of -1. Your end value is 1 but in the for loop it checks if cooldown is 0 which will not be reached as the for loop already stopped.
This should work:
local status = game.ReplicatedStorage.Status
local cooldown = 5 -- 240
local currentDay = game.ReplicatedStorage.Day
local mSpeed = game.ReplicatedStorage.MonsterSpeed
local isSleeping = game.ReplicatedStorage.isSleeping
local function timer()
for i = cooldown, 0, -1 do
print(cooldown)
print(status.Value)
if cooldown == 0 then
status.Value = "Night"
end
task.wait(1)
end
end
spawn(timer)
You are counting down until you are at number 1, the second number is the End Value, meaning it will stop the loop when it reaches 1. So countdown will never reach 0, the second value should be 0