So I have a tool that give the player money when they click with a tool…
My issue is that, as the title says, Tool.Activated fires more than once, which means the player gets alot more than what they should when they click.
I believe using a debounce would prevent this but I dont know how to use it and the documentation on it doesnt really help.
Here is the piece of code that uses Tool.Activated
local Use do
Use = Tool.Activated:Connect(function()
if MoneyStat then
MoneyStat.Value += 750
end
end)
end
debounce = false
Tool.Activated:Connect(function()
if not debounce then
debounce = true
if MoneyStat then
MoneyStat.Value += 750
end
wait(<as long as you need in seconds before they can Activate again>)
debounce = false
end
end)
GN.Event:Connect(function(currentNum)
for i = 1, 25 do
if textLabelContainer[i].Text == tostring(currentNum) then
textLabelContainer[i].TextColor3 = Color3.fromRGB(249, 88, 88)
local SFX = Instance.new("Sound")
SFX.SoundId = "11347614164"
SFX.Parent = Tool
SFX.Playing = true
if SFX.Stopped then
SFX:Destroy()
end
--// Script -- Getting Bingo
local textLabelContainer2 = {}
local BingoNum = {}
local Found
local Iterations = 0
for i,v in pairs(NumList:GetChildren()) do --gets the numbers the player has
if v.Name ~= "UIGridLayout" then
table.insert(textLabelContainer2, v)
end
end
for i = 1, #textLabelContainer2 do --gets the numbers the player has that has been called out
if textLabelContainer2[i].TextColor3 == Color3.fromRGB(249, 88, 88) then
table.insert(BingoNum, textLabelContainer2[i])
end
end
for _, BingoTable in pairs(BingoTypes) do
if Found then break end
Iterations = 0
for Index, Value in ipairs(BingoNum) do
if table.find(BingoTable, tostring(Value)) then
Iterations += 1
end
if Iterations == #BingoTable then
Found = BingoTable
break
end
end
end
if Found then
local Use do
Use = Tool.Activated:Connect(function()
print(Player.Name.. " - Bingo Check: True")
print(Player.Name.. " - Resetting Card")
for i = 1, 25 do
textLabelContainer[i].TextColor3 = Color3.fromRGB(0,0,0)
if textLabelContainer[i].Name == "13/FREE" then
textLabelContainer[i].Text = "FREE"
textLabelContainer[i].TextColor3 = Color3.fromRGB(249, 88, 88)
end
end
if MoneyStat then
MoneyStat.Value += 750
end
CR:FireAllClients()
table.clear(BingoNum)
Use:Disconnect()
end)
end
else
local Use do
Use = Tool.Activated:Connect(function()
print(Player.Name.. " - Bingo Check: False")
local SFX = Instance.new("Sound")
SFX.SoundId = "550209561"
SFX.Parent = Tool
SFX.Volume = 0.1
SFX.Playing = true
if SFX.Stopped then
SFX:Destroy()
end
end)
end
end
end
end
end)
end)
Thanks, for some reason I had the event fired every second instead of 10 seconds and since the refresh/rerun system isnt as quick it spammed some lines of code