Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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

Ad

Answer this question