So i made a basic teleporter, but it just makes the player's humanoidrootpart teleport, leaving behind the player's playermodel. any help?
01 | script.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 = Vector 3. new(teleportB.Position.X, teleportB.Position.Y + 5 , teleportB.Position.Z) |
10 | end |
11 | end |
12 | end ) |
CFrame
, not Position
.CFrame
description by ROBLOX:
CFrame
, is a data type that represents a position and orientation in 3D space.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.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.01 | script.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 | Vector 3. new( |
10 | teleportB.Position.X, |
11 | teleportB.Position.Y + 5 , |
12 | teleportB.Position.Z |
13 | ) |
14 | ) |
15 | ) |
16 |
17 | end |
18 | end |
19 | end ) |
Instead of using positions, use CFrame:
01 | script.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 |
12 | 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.
1 | CFrame.new(teleportB.Position.X, teleportB.Position.Y + 5 , teleportB.Position.Z) |
This should work.