I made a brick that when touched it makes you faster and gives you a sword which i called stick, it worked fine but it gave you too many swords so i added the debounce but it didn't do anything when i added it. How can i fix this?
local Canpress = true
script.Parent.Touched:connect(function(hit)
if Canpress == true then
Canpress = false
hit = hit.Parent:FindFirstChild("Humanoid")
hit.WalkSpeed = hit.WalkSpeed*1.25
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local ClonedSword = game.ServerStorage.Stick:Clone()
ClonedSword.Parent = player.Backpack
Canpress = true
end
end)

1 comment
When you check for the debounce, also check if there is a sword already in the players backpack. Also, check to see if there really is a humanoid before doing anything with it, FindFirstChild can return nil.