Teleporter part not working

Hello, im trying to make a secret area where if you touch a part you teleport to there.

the problem is its not teleporting the player there. how can i fix this?

my code:

local Teleport = "teleport2"
function Touch (hit) 
	if script.Parent.Locked == false and script.Parent.Parent : FindFirstChild(Teleport).Locked == false then script.Parent.Locked = true script.Parent.Parent:FindFirstChild(Teleport).Locked=true
		local Pos = script.Parent.Parent:FindFirstChild(Teleport)
		hit.parent:moveTo(Pos.Position) wait(1)script.Parent.Locked = false script.Parent.Parent:FindFirstChild(Teleport).Locked = false
	end
end
script.Parent.Touched:connect(Touch)

If something is Locked it just means you can’t select it in Studio, so it’s not needed for in-game scripts.

The “MoveTo” function doesn’t teleport players but walks the player to that location, if you want to teleport the Player ,change the HumanoidRootPart CFrame to the CFrame of the Teleport2 part

here’s a script that should work

local Teleport = "teleport2"
function Touch(hit) 
	if hit.Parent:FindFirstChild("Humanoid") then 
		local Pos = script.Parent.Parent:FindFirstChild(Teleport)
		hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(Pos.Position)
	end
end
script.Parent.Touched:Connect(Touch)

Now if you touch the part it will infinite loop teleport you. how do i make you need to wait to teleport again? like 5 seconds long.

1 Like

you add a debounce, let me make one real quick (srry for the wait)

local Teleport = "teleport2"
local debounce = false

function Touch (hit) 
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then 
		debounce = true
		local Pos = script.Parent.Parent:FindFirstChild(Teleport)
		hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(Pos.Position)
		wait(5) -- you can change this to however long you want the wait time to be
		debounce = false
	end
end
script.Parent.Touched:Connect(Touch)
script.Parent.Touched:Connect(function(hit)
local Plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player
     if Plr then
Plr.Character:MoveTo(Pos.Position + Vector3.new(0,2,0) -- so the player doesnt spawn inside the part
     end
end)

i got this error:

Cframe is not a valid member of Part “Workspace.wanu10.HumanoidRootPart”

srry about that , my autocorrect change “CFrame” to “Cframe”
this should work

local Teleport = "teleport2"
local debounce = false

function Touch (hit) 
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then 
		debounce = true
		local Pos = script.Parent.Parent:FindFirstChild(Teleport)
		hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(Pos.Position)
		wait(5) -- you can change this to however long you want the wait time to be
		debounce = false
	end
end
script.Parent.Touched:Connect(Touch)

The time to wait does not work.

@DevForumWanu10 Try this:

Debounce = false
WaitTime = 2 -- Change this if you like

script.Parent.Touched:Connect(function(hit)

if not Debounce then

Debounce = true

local Plr = game.Players:GetPlayerFromCharacter(hit.Parent) -- Gets the player
     if Plr then
Plr.Character:MoveTo(Pos.Position + Vector3.new(0,2,0)) -- so the player doesnt spawn inside the part
     end

task.wait(WaitTime)

Debounce = false
end
end)

Please may you paste in the exact script you used?

teleport1 = teleport you to teleport block 2
teleport2 = teleport you to teleport block 1
NOT SCRIPT
and this is the code in teleport1

local Teleport = "teleport2"
local debounce = false

function Touch (hit) 
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then 
		debounce = true
		local Pos = script.Parent.Parent:FindFirstChild(Teleport)
		hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(Pos.Position)
		wait(5) -- you can change this to however long you want the wait time to be
		debounce = false
	end
end
script.Parent.Touched:Connect(Touch)

and this is the code for teleport2

local Teleport = "teleport1"
local debounce = false

function Touch (hit) 
	if hit.Parent:FindFirstChild("Humanoid") and not debounce then 
		debounce = true
		local Pos = script.Parent.Parent:FindFirstChild(Teleport)
		hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(Pos.Position)
		wait(5) -- you can change this to however long you want the wait time to be
		debounce = false
	end
end
script.Parent.Touched:Connect(Touch)
1 Like

The wait is for when you can use the teleporter again , so it doesn’t keep teleporting you every second
pls may you explain in what way the wait isn’t working?

When i touch the teleporter it teleports me to the other one but teleports me back.

1 Like

Damn yall ignoring me, thats kinda sad

i tried your script right after you posted it. it does not work.

Im testing it rn, it does.

Edit:
Oh i see, this should work:

Debounce = false
WaitTime = 2 -- Change this if you like

script.Parent.Touched:Connect(function(hit)

if not Debounce then

Debounce = true

local Plr = game.Players:GetPlayerFromCharacter(hit.Parent)
     if Plr then
Plr.Character:MoveTo(Pos.Position + Vector3.new(0,2,0)) 
     end

task.wait(WaitTime)

Debounce = false
end
end)

Unless im missing something

ahhh, I sort of see why you were using Locked , as a Variable to see if it was just teleported to
I’ll try make it so it doesn’t do that , one sec

I don’t know the solution but there’s a lot of working teleporters in the free models. Maybe you can compare the script of theses free models to your teleporter.

1 Like

i think that may not work because “Pos” isn’t defined, but other than that it should be able to

Its an Example Pos is the example Variable