Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I'm making a 30 second countdown script and It's not working. Anyone know why?

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

Video of the issue

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.