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

Debounce for on touched event not working??

Asked by
pie9909 18
4 years ago

Not sure what's going on here but it could just be me being dumb, my debounce isn't working. other than that everything is working fine

is it because of how I placed the debounce?

game.Players.PlayerAdded:Connect(function(player)
    script.Parent.Touched:Connect(function(hit)

        local char = hit.Parent
        local hum = char:FindFirstChild("Humanoid")

        local debounce = false

        if hum and not debounce then


            local players = game:GetService("Players")
            local player = players:GetPlayerFromCharacter(char)
            local pack = player.Backpack
            local findSword = pack:FindFirstChild(player.Name.."'s sword")
            local char = player.Character or player.CharacterAdded:Wait()
            local equippedSword = char:FindFirstChild(player.Name.."'s sword")
            if not findSword  and not equippedSword then  


                local SwordE = player:WaitForChild("EquippedSword")
                if SwordE then
                    local Swordbank = game.ReplicatedStorage:WaitForChild("SWORDBANK")
                    for _,Bank in pairs(Swordbank:GetChildren()) do
                        if Bank:IsA("Tool") then
                            if Bank.Name == SwordE.Value then


                                local CloneBank = Bank:Clone()
                                CloneBank.Name = (player.Name.."'s sword")
                                CloneBank.Parent = char


                                debounce = true
                                wait(5)
                                debounce = false

                            end
                        end 
                    end
                end
            end
        end
    end)
end)

1 answer

Log in to vote
0
Answered by 4 years ago

Yes, it IS because of how the debounce is placed. debounce is always set to false when the event fires. You need to declare the variable outside the events.

0
Ohh i see, alright thanks a ton pie9909 18 — 4y
Ad

Answer this question