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

Debounce Not Working Correctly?

Asked by 4 years ago

Hello,

I am having trouble setting up my debounce so I can stop people from spamming, any help would be appreciated.

for i, SearchGarbage in pairs(game.Workspace.InteractObjects.GarbageCans:GetChildren()) do
    SearchGarbage.ClickDetector.MouseClick:Connect(function(Player)
        local Chance = math.random(1,5)
        local TrashSearch = true
        if TrashSearch then
            TrashSearch = false
            Search:Play()
            wait(3)
            if Chance == 3 then
                ReplicatedStorage.GUI.Notification:Clone().Parent = Player.PlayerGui
                ReplicatedStorage.GUI.Notification.FoundItem.Label.Text = "Found Junk"
                CloneObjEvent:FireServer(ReplicatedStorage.Items.Junk)
            else
                ReplicatedStorage.GUI.Notification:Clone().Parent = Player.PlayerGui
                ReplicatedStorage.GUI.Notification.FoundItem.Label.Text = "Found Nothing"
            end
        end
        TrashSearch = true
    end)
end
0
Try having the original var declaration outside of the for loop. Farsalis 369 — 4y

1 answer

Log in to vote
1
Answered by
Farsalis 369 Moderation Voter
4 years ago

Try having the original var declaration outside of the for loop. Since, whenever it detects a click, TashSearch will always be true (Since Its Always Being Declared As True).

0
tried it, still able to spam it. Decimaprism 65 — 4y
Ad

Answer this question