local tool = script.Parent local plr = game:GetService('Players').LocalPlayer local mouse = plr:GetMouse() local function Tele() tool.Parent:moveTo(mouse.hit.Position) end tool.Activated:Connect(Tele)
One way of adding a cooldown would be to use a variable, and set it to true once the action is being completed and then set it to false after a set amount of time has passed. At the start of the function, you'll want to make sure that the variable is false.
local tool = script.Parent local plr = game:GetService('Players').LocalPlayer local mouse = plr:GetMouse() local cooldown = 5--How many seconds you want the cooldown to be local db=false local function Tele() if db==false then db=true tool.Parent:moveTo(mouse.hit.Position) wait(cooldown) db=false end tool.Activated:Connect(Tele)
In this example, once the function runs, it makes db=true and then after 5 seconds, db=false. If we check for db to be equal to false at the start, this means that for 5 seconds, the function will not be able to run
You can add a debounce for each time you teleported.
local tool = script.Parent local plr = game:GetService('Players').LocalPlayer local mouse = plr:GetMouse() local deb = false local cooldown = 5 local function Tele() if deb then return end -- if deb is true then stop this function and continue tool.Parent:moveTo(mouse.hit.Position) deb = true wait(cooldown) deb = false end tool.Activated:Connect(Tele)