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

How do I make this script only respawn tools one time, not endlessly?

So I use this script to make my weapons respawn

local gear = {}
for i,v in pairs (workspace:GetChildren()) do
    if v:IsA("Tool") then
        gear[i] = v:clone()
        v.AncestryChanged:connect(function()
            Delay(30, function()  -- 30 = time until respawn
                gear[i]:clone().Parent = workspace
            end)
        end)
    end
end

However, how do I make it so that once the tool has been taken, after a certain amount of time, it will spawn another one, BUT, only one, until it gets taken again, and then the timer starts again.

1 answer

✓ Accepted answer
T=true
local gear = {}
for i,v in pairs (workspace:GetChildren()) do
    if v:IsA("Tool") and T==true then
	T=false
        gear[i] = v:clone()
        v.AncestryChanged:connect(function()
            Delay(30, function()  -- 30 = time until respawn
                gear[i]:clone().Parent = workspace
            end)
	T=false
        end)
    end
end


Try this...not sure if it'll work, but give it a shot. If this doesn't work then just try debouncing it at different areas in the script.

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