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

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

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)

2 comments

0

 

0

use debounces

1 answer

✓ Accepted answer

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)

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