Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How come this script doesnt teleport the player?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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)

0
this worked, thanks for being in depth with your answer! DaBrainlessOne 129 — 6y
Ad
Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
6 years ago

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)
Log in to vote
0
Answered by 6 years ago

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.

Answer this question