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

How would i add a delay to this tool script?

Asked by 5 years ago

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.

01local sound = workspace.Sound
02local tool = script.Parent
03 
04 
05tool.Activated:Connect(function()
06    local character = tool.Parent
07    local players = game:GetService("Players")
08    local player = players:GetPlayerFromCharacter(character)
09    local leaderstats = player.leaderstats
10    local currency = leaderstats.GamerScore
11    local addition = 500
12 
13    sound.Playing = true
14    currency.Value = currency.Value + addition
15 
16 
17end)
0
delay() or wait() speedyfox66 237 — 5y

2 answers

Log in to vote
1
Answered by
nc2r 117
5 years ago

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

01local sound = workspace.Sound
02local tool = script.Parent
03local enabled = true
04 
05tool.Activated:Connect(function()
06    if not enabled then return end
07    enabled = false
08    local character = tool.Parent
09    local players = game:GetService("Players")
10    local player = players:GetPlayerFromCharacter(character)
11    local leaderstats = player.leaderstats
12    local currency = leaderstats.GamerScore
13    local addition = 500
14 
15    sound.Playing = true
View all 21 lines...
Ad
Log in to vote
0
Answered by 5 years ago

just add a wait or delay.

01local sound = workspace.Sound
02local tool = script.Parent
03 
04 
05tool.Activated:Connect(function()
06    local character = tool.Parent
07    local players = game:GetService("Players")
08    local player = players:GetPlayerFromCharacter(character)
09    local leaderstats = player.leaderstats
10    local currency = leaderstats.GamerScore
11    local addition = 500
12 
13    sound.Playing = true
14    currency.Value = currency.Value + addition
15 
16wait(5) -- (or you could add delay(5), depending what you choose)
17 
18end)
0
You still need debounce karlo_tr10 1233 — 5y

Answer this question