Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How come this script doesnt teleport the player?

So i made a basic teleporter, but it just makes the player's humanoidrootpart teleport, leaving behind the player's playermodel. any help?

script.Parent.Touched:Connect(function(toucher)
	if toucher.Parent:FindFirstChild("Humanoid") then
		if script.Parent.BrickColor ~= BrickColor.Green() then
			while true do
				wait()
			end
		else
			local teleportB = script.Parent.Parent.TelePartB
			toucher.Parent.HumanoidRootPart.Position = Vector3.new(teleportB.Position.X, teleportB.Position.Y + 5, teleportB.Position.Z)
		end
	end
end)

3 answers

✓ Accepted answer

###You should be using CFrame, not Position.

CFrame description by ROBLOX:

#####CFrame, is a data type that represents a position and orientation in 3D space.

#####All objects inherited from BasePart have a property named CFrame of this type. This property defines where the object is (its position), and how it is rotated (its orientation). The position information is also shown in the Position property, and the rotation information is shown in the Rotation property.

###Also, why is the while loop there? Code written after, but not in the loop won't run until it breaks. I saw it as redundant so I removed it.

script.Parent.Touched:Connect(function(toucher)
    if toucher.Parent:FindFirstChild("Humanoid") then
        if script.Parent.BrickColor ~= BrickColor.Green() then
          -- do something 
        else
            local teleportB = script.Parent.Parent.TelePartB
            toucher.Parent:SetPrimaryPartCFrame(
                CFrame.new(
                    Vector3.new(
                        teleportB.Position.X, 
                        teleportB.Position.Y + 5, 
                        teleportB.Position.Z
                        )
                    )
                )

        end
    end
end)

1 comment

0

this worked, thanks for being in depth with your answer!

Instead of using positions, use CFrame:

script.Parent.Touched:Connect(function(toucher)
    if toucher.Parent:FindFirstChild("Humanoid") then
        if script.Parent.BrickColor ~= BrickColor.Green() then
            while true do
                wait()
            end
        else
            local teleportB = script.Parent.Parent.TelePartB
            toucher.Parent.HumanoidRootPart.CFrame = CFrame.new(teleportB.Position.X, teleportB.Position.Y + 5, teleportB.Position.Z)
        end
    end
end)

Don't Use Vector3 For teleporting things because Vector3 doesn't like it when you try and teleport INTO things so it moves it up so that might have been causing the teleport not to work properly. On the other hand CFrame works with this It allows the part go into other parts instead of above it.

CFrame.new(teleportB.Position.X, teleportB.Position.Y + 5, teleportB.Position.Z)

This should work.

This discussion is preserved as it was. New answers, comments, and votes are closed.