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

How to fix this script? When i add debounce it stops working.

Asked by 7 years ago

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)
0
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. GoldenPhysics 474 — 7y

Answer this question