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

How would i add a delay to this tool script?

This is an emergency, I added a global leaderboard to my roblox game but people are downloading autoclicker, I need to find a way to delay the tool from being spammed, here's the script.

 
	local sound = workspace.Sound
	local tool = script.Parent 
	 
	
	tool.Activated:Connect(function() 
	    local character = tool.Parent 
	    local players = game:GetService("Players") 
	    local player = players:GetPlayerFromCharacter(character) 
	    local leaderstats = player.leaderstats 
	    local currency = leaderstats.GamerScore
	    local addition = 500
	
	    sound.Playing = true
	    currency.Value = currency.Value + addition 

	 
	end)


1 comment

0

delay() or wait()

2 answers

✓ Accepted answer

To prevent it from being spammed, you need to make a variable to see it has been used recently

local sound = workspace.Sound
local tool = script.Parent 
local enabled = true

tool.Activated:Connect(function() 
    if not enabled then return end
    enabled = false
    local character = tool.Parent 
    local players = game:GetService("Players") 
    local player = players:GetPlayerFromCharacter(character) 
    local leaderstats = player.leaderstats 
    local currency = leaderstats.GamerScore
    local addition = 500

    sound.Playing = true
    currency.Value = currency.Value + addition 
    wait(5)
    enabled = true


end)

just add a wait or delay.

local sound = workspace.Sound
local tool = script.Parent 


tool.Activated:Connect(function() 
    local character = tool.Parent 
    local players = game:GetService("Players") 
    local player = players:GetPlayerFromCharacter(character) 
    local leaderstats = player.leaderstats 
    local currency = leaderstats.GamerScore
    local addition = 500

    sound.Playing = true
    currency.Value = currency.Value + addition 
	
wait(5) -- (or you could add delay(5), depending what you choose)

end)

1 comment

0

You still need debounce

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