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?

01script.Parent.Touched:Connect(function(toucher)
02    if toucher.Parent:FindFirstChild("Humanoid") then
03        if script.Parent.BrickColor ~= BrickColor.Green() then
04            while true do
05                wait()
06            end
07        else
08            local teleportB = script.Parent.Parent.TelePartB
09            toucher.Parent.HumanoidRootPart.Position = Vector3.new(teleportB.Position.X, teleportB.Position.Y + 5, teleportB.Position.Z)
10        end
11    end
12end)

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.

01script.Parent.Touched:Connect(function(toucher)
02    if toucher.Parent:FindFirstChild("Humanoid") then
03        if script.Parent.BrickColor ~= BrickColor.Green() then
04          -- do something
05        else
06            local teleportB = script.Parent.Parent.TelePartB
07            toucher.Parent:SetPrimaryPartCFrame(
08                CFrame.new(
09                    Vector3.new(
10                        teleportB.Position.X,
11                        teleportB.Position.Y + 5,
12                        teleportB.Position.Z
13                        )
14                    )
15                )
16 
17        end
18    end
19end)
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:

01script.Parent.Touched:Connect(function(toucher)
02    if toucher.Parent:FindFirstChild("Humanoid") then
03        if script.Parent.BrickColor ~= BrickColor.Green() then
04            while true do
05                wait()
06            end
07        else
08            local teleportB = script.Parent.Parent.TelePartB
09            toucher.Parent.HumanoidRootPart.CFrame = CFrame.new(teleportB.Position.X, teleportB.Position.Y + 5, teleportB.Position.Z)
10        end
11    end
12end)
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.

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

This should work.

Answer this question