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

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

Asked by 10 years ago

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

Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
10 years ago
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.

Ad

Answer this question