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

Adding a cooldown to a weapon spawner?

Asked by
22To 70
9 years ago

ok so i tried to add a cooldown to this weapon spawner but it wont work. i bbasically want it that when someone touch it they get the gun from lighting but i want it that after one person touch it the part wont give another gun until cooldown is done. heres is what i tried.

ToolName = "Tool" -- Exact name of the weapon/tool
RespawnTime = 3 -- Respawn time (In seconds)

function onTouched(part)
p = game.Players:playerFromCharacter(part.Parent)
        if p == nil then return end
Wep = game.Lighting.Pistol:clone() --Change Sword to the name of your weapons
wait(RespawnTime)
Wep = game.Lighting.Pistol:clone() --Change Sword to the name of your weapons
        if p.Backpack:findFirstChild(Wep.Name) ~= nil then return end
        Wep.Parent = p.Backpack
end

1 answer

Log in to vote
0
Answered by
Kyokamii 133
9 years ago

Here's a fix; I didnt test it, but it should work.

ToolName = "Tool" -- Exact name of the weapon/tool
RespawnTime = 3
Debounce = false
script.Parent.Touched:connect(function(hit)
if Debounce == false then
Debounce = true
p = game.Players:playerFromCharacter(hit.Parent)
        if p == nil then return end
else
Wep = game.Lighting.Pistol:Clone() --Change Sword to the name of your weapons
        if p.Backpack:findFirstChild(Wep.Name) ~= nil then return end
else
        Wep.Parent = p.Backpack
end
end
wait(RespawnTime)
Debounce = false
end
end)

I changed some stuff 'cause your script just didn't make sense. if this does not work, tell me (Comment) , don't downvote my Anwser. Ill try to fix it. I didn't see some errors, maybe I missed some.

Ad

Answer this question