I have a teleporter that I'm trying to make that sends you to a shop in my game. The problem is the brick I'm trying to make it teleport you to also sends you back. I've added a debounce to make sure players can't infinity get teleported between the two bricks. I've tried this script and it doesn't teleport you like I'm trying to make it do and there's error in output. If anyone has a clue as to why this doesn't work, that would be awesome.
local teleportbrick1 = workspace:WaitForChild("TeleportBrick1")
local teleportbrick2 = workspace:WaitForChild("TeleportBrick2")
local waittime = 3
local touched = false
local function teleport(position)
return function(hit)
if not touched then
touched = true
local character = game.Players:GetPlayerFromCharacter(hit.Parent).Character
local head = character and character:FindFirstChild("Head")
if head then
head.CFrame = position
end
wait(waittime)
touched = false
end
end
end
teleportbrick1.Touched:connect(teleport(CFrame.new(61.5, 70.7, -123.5)))
teleportbrick1.Touched:connect(teleport(CFrame.new(-69.5, 15.6, -44.5)))

2 comments
Usually, when making a debounce, you make a variable, not a bool value for it.
I understand that, but if I use a debounce it will instantly teleport the player back after they were teleported to the shop because it's a two way teleporter.