Hi, I’m making a wave based zombie game and when the wave increases I want the time to spawn zombies to get lower every time by 0.1, until it reach’s one 0.5 seconds. I’ve had a go but couldn’t seem to get it to work. My script will keep the time staying at 9.9 seconds. Here is the script(the wave and round script is in a different script, didn’t think it was relevant):
local RS = game:GetService("ReplicatedStorage")
local wave = RS:WaitForChild("Values"):WaitForChild("Wave")
local waveminus = 0.1
while true do
if RS.Values.gameInProgress1.Value == true then
local SpawnPoints = workspace.SpawnPoints:GetChildren()
local NumberOfSpawnPoints = #SpawnPoints
local RSP = math.random(1, NumberOfSpawnPoints)
local ChosenSpawnPoint = SpawnPoints[RSP]
local Zombies = RS:WaitForChild("Mobs"):GetChildren()
local NumberOfZombies = #Zombies
local RZ = math.random(1, NumberOfZombies)
local ChosenZombie = Zombies[RZ]
local ClonedZombie = ChosenZombie:Clone()
local FS = ClonedZombie:WaitForChild("Enemy"):WaitForChild("FollowScript")
ClonedZombie.Parent = ChosenSpawnPoint
ClonedZombie:PivotTo(ChosenSpawnPoint.CFrame)
wait(1)
--FS.Enabled = true
game.ReplicatedStorage.Values.ZombiesSpawned.Value = game.ReplicatedStorage.Values.ZombiesSpawned.Value + 1
--end
--end
--local wave = game.ReplicatedStorage.Values.Wave
local ZR = game.ReplicatedStorage.Values.ZombiesRemaning
if ZR.Value == 10 and wave.Value then
wait(10)
ZR = 0
end
--local waitTime = math.random(1,5)
--wait(waitTime)
local TimeToWait = 10
local WaveIncrements = TimeToWait - waveminus
wave.Changed:Connect(function()
task.wait(WaveIncrements)
end)
end
end
The script that your using sets the TimeToWait to 10 and decreases it by 0.1 over and over again instead of decreasing the remaining time. This is because you are repeatedly setting the variable to 10 every time the code repeats, with local TimeToWait = 10.
local TimeToWait = 10 -- You repeatedly set the variable to 10
local WaveIncrements = TimeToWait - waveminus -- Decrease that 10 by 9.9
wave.Changed:Connect(function()
task.wait(WaveIncrements)
end)
-- Your answer will always be 9.9
Define the variable once at the beginning, then every time you want to decrease it, instead of the code you’ve provided, replace it with:
if TimeToWait ~= 0.5 then -- If it hasn't reached 0.5 yet
TimeToWait = TimeToWait - 0.1 -- Decrease the current TimeToWait by 0.1
end
It should work after each wave. All it does is decrease the current time by 0.1. You’re gonna have to then wait for that amount of time before beginning the new wave, but I’m sure you can do that.
what will happen once it get to 0.5? will that stop the script from running? Because once it gets to 0.5 I want it to keep going just not subtract the 0.1.
The script I provided should skip the whole -0.1 thingy mabob and continue with the script. If the “if” condition isn’t satisfied it should keep the TimeToWait the same and continue on with whatever is next.