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

Touching a part to teleport not working?

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

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))

1 comment

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.

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)

5 comments

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)

0

ummmm it should work

0

ohhh i forgot to put a closing parenthesis to close off the call to connect, the code has been updated

0

Error: (1,27) Incomplete statement: expected assignment or a function call

0

the problem must be in some other code that you have.. i tested this and worked with fine colors

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!

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

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