Teleporter not working

Hello! So I was working with a few teleporters to move players around in a game, and one of them just isn’t working, despite having the same code as every other teleporter in my game but with a changed variable for the location of the teleport. Here’s some screenshots and a video of the issue:

robloxapp-20210203-1404412.wmv (2.2 MB)

local teleport = game.Workspace.tptwo

function onTouch(part)
   if part.Parent.Humanoid ~=nil then
         part.Parent:MoveTo(teleport.Position)
    end
end
script.Parent.Touched:connect(onTouch)

teleportglitch2.PNG|690x377

Any help is appreciated!

It would be appreciated if you didn’t send screenshots of your code, as outlined in category guidelines. Please format them correctly.

part.Parent is the character. What I can see is that you’re trying to move the character, not the part of the character. Instead, try

part.Parent.Torso:MoveTo(teleport.Position)

or if you’re using R15, use UpperTorso or LowerTorso

I’m not sure that’s the problem though, as I’m using the same code on all of my other teleporters and this is the only one acting up

click view on top and click output, then show us what error you get after trying to teleport using the bugged part.

1 Like

Alright, so first of all, use FindFirstChildOfClass. This will prevent an error occuring when the game tries to find a Humanoid. Like this:

script.Parent.Touched:connect(function(hit)
       local hum = hit.Parent:FindFirstChildOfClass("Humanoid")
       if hum ~= nil then -- make sure the humanoid is there 
             hum.Parent:SetPrimaryPartCFrame(teleport.CFrame) -- both compatible with R6 and R15
       end
end)

I tested it, and it works perfectly. You may have to raise the part a bit to get the expected result.

1 Like

Try this:

local teleport = game.Workspace.tptwo

function onTouch(part)
       if part.Parent:FindFirstChild("Humanoid") then
            part.Parent.Humanoid.Position = teleport.Position
      end
end

script.Parent.Touched:Connect(onTouch)
2 Likes

Thank you so much!!! This worked like a charm

1 Like

I don’t know why you were using :MoveTo I don’t know if that works because I have never tried it but you should just change the position to the position you want it to go to.

1 Like