local Players = game:GetService("Players")
local ReplicatedStroge = game:GetService("ReplicatedStorage")
local functions = ReplicatedStroge:WaitForChild("Functions")
local wave = workspace.Info.Wave
local info = workspace.Info
local gameOver = false
local seconds = info.Time.Seconds
local function timer()
seconds.Value = 0
repeat
seconds.Value += 1
task.wait(1)
until #workspace.Mobs:GetChildren() == 0 or not info.GameRunning.Value
end
info.Wave.Changed:Connect(function()
timer()
end)
However, after each wave I think its duplicating itself because it then goes from 1 count every second to 2 and then 3, etc. How can I fix this?
local Players = game:GetService("Players")
local ReplicatedStroge = game:GetService("ReplicatedStorage")
local functions = ReplicatedStroge:WaitForChild("Functions")
local wave = workspace.Info.Wave
local info = workspace.Info
local gameOver = false
local debounce = false
local seconds = info.Time.Seconds
local function timer()
seconds.Value = 0
repeat
seconds.Value += 1
task.wait(1)
until #workspace.Mobs:GetChildren() == 0 or not info.GameRunning.Value
debounce = false
end
info.Wave.Changed:Connect(function()
if not debounce then
debounce = true
timer()
end
end)
...
local db = false
local function timer()
if db == true then return end
db = true -- stop any code to run the code while the code running
seconds.Value = 0
while #workspace.Mobs:GetChildren() >0 do -- check if the mobs greater then 0
seconds.Value += 1
task.wait(1)
end -- stuck
db = false -- change it so it can run again
end
...
local Players = game:GetService("Players")
local ReplicatedStroge = game:GetService("ReplicatedStorage")
local functions = ReplicatedStroge:WaitForChild("Functions")
local wave = workspace.Info.Wave
local info = workspace.Info
local gameOver = false
local seconds = info.Time.Seconds
local db = false
local function timer()
if db == true then return end
db = true -- stop any code to run the code while the code running
seconds.Value = 0
while #workspace.Mobs:GetChildren() >0 do -- check if the mobs greater then 0
seconds.Value += 1
task.wait(1)
end -- stuck
db = false -- change it so it can run again
end
info.Wave.Changed:Connect(function()
timer()
end)
local Players = game:GetService("Players")
local ReplicatedStroge = game:GetService("ReplicatedStorage")
local functions = ReplicatedStroge:WaitForChild("Functions")
local wave = workspace.Info.Wave
local info = workspace.Info
local gameOver = false
local debounce = false
local seconds = info.Time.Seconds
local function timer()
seconds.Value = 0
repeat
seconds.Value += 1
task.wait(1)
until #workspace.Mobs:GetChildren() == 0 or not info.GameRunning.Value
debounce = false
end
info.Wave.Changed:Connect(function()
if not debounce then
debounce = true
timer()
end
end)
It works well but when you skip the wave and not all the enemies are killed, it keeps counting and doesn’t restart to zero. I tried doing this:
local Players = game:GetService("Players")
local ReplicatedStroge = game:GetService("ReplicatedStorage")
local functions = ReplicatedStroge:WaitForChild("Functions")
local wave = workspace.Info.Wave
local info = workspace.Info
local debounce = false
local seconds = info.Time.Seconds
local currentWave
local function timer()
seconds.Value = 0
currentWave = info.Wave.Value
repeat
seconds.Value += 1
task.wait(1)
until #workspace.Mobs:GetChildren() == 0 or not info.GameRunning.Value or currentWave ~= info.Wave.Value
debounce = false
end
info.Wave.Changed:Connect(function()
if not debounce then
debounce = true
timer()
end
end)
But the timer just froze at the new wave, what else can I do?
By the way the issue is that when the wave is skipped, it doesn’t restart back to zero due to it not meeting the requirements. For some reason, the script above didnt work.
local Players = game:GetService("Players")
local ReplicatedStroge = game:GetService("ReplicatedStorage")
local functions = ReplicatedStroge:WaitForChild("Functions")
local wave = workspace.Info.Wave
local info = workspace.Info
local debounce = false
local seconds = info.Time.Seconds
local currentWave
local function timer()
seconds.Value = 0
currentWave = info.Wave.Value
repeat
seconds.Value += 1
task.wait(1)
until #workspace.Mobs:GetChildren() == 0 or not info.GameRunning.Value or seconds.Value >= (seconds u want for the wave to end)
debounce = false
end
info.Wave.Changed:Connect(function()
if not debounce then
debounce = true
timer()
end
end)
Hey, thanks for all the help but I was able to solve it. I remembered I had a value called “Skip” for skipping waves obviously which I added to the list of conditions and it worked fine. Thanks anyways though!