So Im making a teleporting portal where a GUI Pops up when they are teleporting. But they do teleport but the only issue is, it teleports them back as soon as they arrive to the part.
Door1 Script:
local TeleportationEvent = game.ReplicatedStorage.TeleportationDoorEvent
local Door1 = script.Parent
local Door2 = game.Workspace.TeleportPartCandy
local debounce = false
local cooldown = 8
Door1.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
wait(cooldown)
if not debounce then
debounce = true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
TeleportationEvent:FireClient(plr)
wait(0.1)
hit.Parent.HumanoidRootPart.CFrame = Door2.CFrame
wait(2)
debounce = false
end
end
end
end)
Door2 Script:
local TeleportationEvent = game.ReplicatedStorage.TeleportationDoorEvent
local Door1 = script.Parent
local Door2 = game.Workspace.TeleportPart1
local debounce = false
local cooldown = 8
Door1.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not debounce then
debounce = true
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
TeleportationEvent:FireClient(plr)
wait(0.1)
hit.Parent.HumanoidRootPart.CFrame = Door2.CFrame
wait(1)
debounce = false
end
end
end
end)
I created a Event and the teleport works! The only issue is I need a cooldown before the event starts over again. Please help me find my error.