You can use a debounce. A debounce is, in simplest terms, an on/off switch for a function.
Considering this is a LocalScript, you can use a debounce variable. If you choose to debounce on a server script in the future, you will need to debounce using a different method (BoolValue, DataStore, etc).
To start, you will want to define the debounce variable outside of the Tool.Equipped and Mouse1Down events.
Second, inside the Mouse1Down event, you should check if the switch is "on." If the switch is on, then you don't want them to continue:
if debounce then return end
If the switch is off, then you will want to turn it on before you run the rest of your code by setting the debounce variable to true.
Finally, once all your other code has been executed, proceed to add a wait(6), and simply set the switch back to off so that the next time Mouse1Down is fired it will be able to run.
local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Tool = script.Parent
local debounce = false
Tool.Equipped:Connect(function()
Mouse.Button1Down:Connect(function()
if debounce then return end
debounce = true
if Mouse.Target.Parent.Parent.Name == "F | Gate" then
local HingeLeft = Mouse.Target.Parent.Parent.Left.LeftHingePart
local HingeRight = Mouse.Target.Parent.Parent.Right.RightHingePart
if HingeLeft.Parent.Parent.OpenvClosed.Value == "C" then
game.ReplicatedStorage.Remotes.Gate:FireServer(HingeLeft,HingeRight)
else
game.ReplicatedStorage.Remotes.GateC:FireServer(HingeLeft,HingeRight)
end
end
wait(6)
debounce = false
end)
end)
2 comments
Thank you! (:
No problem, just use true and false values, if debounce == false means if the cooldown = false then do it and then it sets cooldown to true, waits 6 seconds at the end of the script and sets it to false again, simple!