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


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)
0
delay() or wait() speedyfox66 237 — 4y

2 answers

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

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)
Ad
Log in to vote
0
Answered by 4 years ago

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)
0
You still need debounce karlo_tr10 1233 — 4y

Answer this question