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

Touching a part to teleport not working?

Asked by 4 years ago

Im working on a simulator and im kinda new to scripting , i wanted to make one of those portals you touch with the body and get teleported at specific coordonates , but it doesnt work

game.Workspace.Player.HumanoidTouchPart.CFrame = CFrame.new(Vector3.new(-69, 0.5, -171))

What am i doing wrong?

4 answers

Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
4 years ago

You can't specify a player like that, everything else seems ok. This is how you can do it in localscripts:

local Player = game.Players.LocalPlayer

Player.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-69, 0.5, -171))
0
If you wanted to do it in a ServerScript, you would have to do the .Touched event and get the player from that and send the player to a different location. killerbrenden 1537 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

you need to do PlayersCharacter.HumanoidRootPart.CFrame = Cframe

so do it like this:

local teleporter = --part to touch

teleporter.Touched:Connect(function(part)
    if(part.Parent:FindFirstChild("Humanoid")) then
        part.Parent.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(-69, 0.5, -171))
    end
end)
0
Doesn't work, i put it in ServerScriptService(maybe i did wrong) and changed the --part to touch with the part's name(maybe i did this wrong too) MrJPgSwag -5 — 4y
0
ummmm it should work User#23252 26 — 4y
0
ohhh i forgot to put a closing parenthesis to close off the call to connect, the code has been updated User#23252 26 — 4y
0
Error: (1,27) Incomplete statement: expected assignment or a function call MrJPgSwag -5 — 4y
0
the problem must be in some other code that you have.. i tested this and worked with fine colors User#23252 26 — 4y
Log in to vote
0
Answered by
Rinextel 291 Moderation Voter
4 years ago
Edited 4 years ago

Try this:

local StartingPart = game.Workspace.StartingPart --change if needed
local TeleportingPart = game.Workspace.TeleportingPart -- part you're teleporting to, change if needed

StartingPart.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        hit.Parent:FindFirstChild("HumanoidRootPart").CFrame = TeleportingPart.CFrame
end

What you'll need to do is have a part that this runs when you touch it, and a part for it to teleport you to. So, when you touch the StartingPart it'll teleport you to the CFrame of the TeleportingPart.

Happ scripting, be sure to mark as the answer if this helps!

Log in to vote
0
Answered by
iactz 15
4 years ago

Try:

local player = game.Players.LocalPlayer

TeleportCoordinates = () --Put coords in the ()

player.Character.HumanoidRootPart.CFrame = CFrame.new(TeleportCoordinates)

To get coordinates you could

Do "print(player.Character.HumanoidRootPart.CFrame)"

or

Make a textlabel and make it loop with

local player = game.Players.LocalPlayer
while true do
    wait() --make sure to add the wait or it will crash your game :D
    script.Parent.Text = player.Character.HumanoidRootPart.CFrame
end

Answer this question