I want to make a part where if you click it, the player who clicked it teleports to a certain area in the same game to a part that I would place somewhere. How do I make that work?
Also, is it possible to make the click have some sort of cooldown? For instance the player can click it once every 60 seconds or so…
local part = --locate to part
local ClickDetector = -- locate to click detector
local DB = false
ClickDetector.MouseClick:Connect(function(player)
if DB == false then
DB = true
player.Character.Torso.CFrame = part.CFrame
task.wait(60)
DB = false
end)
local cooldown = 60
local start = tick() - cooldown
local Part0 = script.Parent -- change to the actuall path
local Part1 -- change to the second part path
local Part0Click = Instance.new("ClickDetector", Part0)
Part0Click.MouseClick:Connect(function(Player)
if (tick() - start) >= cooldown then
local Character = Player.Character
if Character and Character.PrimaryPart then
Character.PrimaryPart.CFrame = Part1.CFrame
start = tick()
end
end
end)
local Part1Click = Instance.new("ClickDetector", Part1)
Part1Click.MouseClick:Connect(function(Player)
if (tick() - start) >= cooldown then
local Character = Player.Character
if Character and Character.PrimaryPart then
Character.PrimaryPart.CFrame = Part0.CFrame
start = tick()
end
end
end)
local destinationPart = -- Part to teleport to
local clickDetector = -- The click detector
local teleportCooldown = 60 -- In seconds
local debounce = false
local function onClick(player)
if debounce or (not player.Character) then -- If debounce is true or the character is nil
return -- Stop the function
end
debounce = true
player.Character:MoveTo(destinationPart.Position) -- Move the player to part position
task.delay(teleportCooldown, function()
debounce = false -- Reset debounce after cooldown
end)
end
clickDetector.MouseClick:Connect(onClick)