I've been trying to make a 30-second countdown script for the ammo boxes in my game. Whenever I use the ammo box in testing, it freezes up my game and goes over 400k below 0.
Here's the code for the Ammo Box script and the countdown scripts!
Ammo Box Scipt(killscript as what it likes to refer to itself as)
local countdown = script.Parent:FindFirstChild("Script") script.Parent.Touched:connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild("KAR2989") then hit.Parent.KAR2989.StoredAmmo.Value = hit.Parent.KAR2989.StoredAmmo.Value + 40 --Adds ammo to the stored ammo of the gun countdown.Disabled = false --Puts the countdown script into action script.Disabled = true --disables the script till it's re-enabled by the next script end end)
Countdown Script(it's just called script ingame)
local killscript = script.Parent:FindFirstChild("KillScript") script.Value.Value = 30 repeat --Begins the countdown script.Value.Value = script.Value.Value - 1 until script.Value == 0 --Sets the minimum killscript.Disabled = false --puts the Ammo Box script back into action script.Disabled = true --Disables the script till another guy picks up ammo
You forgot to wait a second in your loop
local killscript = script.Parent:FindFirstChild("KillScript") script.Value.Value = 30 repeat --Begins the countdown wait(1) script.Value.Value = script.Value.Value - 1 until script.Value <= 0 --Sets the minimum killscript.Disabled = false --puts the Ammo Box script back into action script.Disabled = true --Disables the script till another guy picks up ammo