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

Any way i can make so a player only can click once per selectable time?

Asked by 4 years ago
Edited 4 years ago

Ive made this code that spawn a part for my building game, but some greifers spam it and ruin the game, Any way i can make so you cant spam click it and only click it once per specific time, Heres the small code end)

script.Parent.Activated:Connect(function()

    game.ReplicatedStorage.PartCreate2:FireServer()

end)
0
  Max_Mastor 0 — 4y
0
use debounces Lunaify 66 — 4y

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You can use a debounce! What is a debounce? This is a small line of code that will prevent the respective scope family from executing. To construct one, you’ll need an conditional statement, and a two variables.

local tool = script.Parent

local waitTime = 1 --// interval of time before next click
local debounce = false

tool.Activated:Connect(function()

    if (debounce) then return end --// bounce conditional

    game:GetService("ReplicatedStorage").Part2Create:FireServer()

    --// modifier
    debounce = true
    wait(waitTime)
    debounce = false

end)
Ad

Answer this question