I am trying to make a teleport door that teleports/moves you to a different part of the world, but I am having an issue with the player being teleported inside of the other trigger door making a constant loop of the player teleporting to the entrance and exit at the same time. Here is my code:
for i, doorTouched in pairs(Server.teleportDoor:GetDescendants()) do
if doorTouched:IsA("Part") then
doorTouched.Touched:Connect(function(plr)
local hp = plr.Parent:FindFirstChild("HumanoidRootPart")
if doorTouched.Name == "Enter" then
pcall(function()
hp.CFrame = CFrame.new(doorTouched.Parent:FindFirstChild("Exit").Position)
end)
elseif doorTouched.Name == "Exit" then
pcall(function()
hp.CFrame = CFrame.new(doorTouched.Parent:FindFirstChild("Enter").Position)
end)
end
end)
end
end
end
I have tried to use a debounce so the player has to wait before being teleported while preventing a loop, but it seems to not do any effect.