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:
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)
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.
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)
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.