Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Debounce Not Working Correctly?

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

1 comment

0

Try having the original var declaration outside of the for loop.

1 answer

✓ Accepted answer

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).

1 comment

0

tried it, still able to spam it.

This discussion is preserved as it was. New answers, comments, and votes are closed.