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

How to change a character's position?

How to change a character's position, When I'm making a script, it says that position isn't a valid member of a character. Any help?

3 answers

✓ Accepted answer

This is how you teleport or change the players position. We can use 3 different things to teleport. 1. CFrame, 2. MoveTo, 3. SetPrimaryPartCFrame. I know you already accepted an answer but most people don't know that there are 3 ways to teleporting a player.


CFrame. This is easy.

workspace.Player.Torso.CFrame = CFrame.new(0,0,0) --Teleport

Next is moveto function,

workspace.Player:MoveTo(Vector3.new(0,0,0)) --Moves the model

Last is SetPrimaryPartCFrame

workspace.Player:SetPrimaryPartCFrame(CFrame.new(0,0,0)) --Teleports the primary part and also teleport the objects in the model.

I hope it helps!


To teleport ALL the players, do this:

for i, player in ipairs(game.Players:GetChildren()) do
   if player.Character and player.Character:FindFirstChild("Torso") then
      player.Character.Torso.CFrame = CFrame.new(0,0,0) + Vector3.new(0, i * 5, 0)
   end
end

Teleports each player and teleports each player on top of each other so they don't get stuck inside each other.


If you want to teleport players from a game to another game use the TeleportationService. For example:

script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        game:GetService("TeleportService"):Teleport(8473728, player) --Teleport the player to a game with an ID of 8473728
    end
end)

This is what you use for GUIs. THIS IS FOR LOCAL SCRIPT ONLY.

script.Parent.MouseButton1Click:connect(function()
    local player = game.Players.LocalPlayer --LocalPlayer
    if player then
        game:GetService("TeleportService"):Teleport(8473728
    end
end)

3 comments

0

Question, Won't the first thing , I mena CFrame move the player named Player?

0

brokenrares of course, It's just for an example though.

0

You are doing this way to complicated! For GUI's you should do script.Parent.MouseButton1Click:Connect(function() game:GetService("TeleportService"):Teleport(00000000) end end) -- This is in 1 line and way shorter also very easy to understand

Use the MoveTo() method.

Character:MoveTo(Vector3.new(0, 0, 0))

Make sure to define Character and stuff, and you can of course replace the Vector3 values.

EDIT: You could also use CFrame, but that's if you're teleporting to a part. If you need a tutorial on CFrame, just comment.

2 comments

0

Yeah I'd like to know how to do that with CFrame please?

0

Just set the CFrame of the torso. character.Torso.CFrame = CFrame.new(0, 0, 0). Also, look up CFrame on the wiki.

character.HumanoidRootPart.CFrame = CFrame.new(0,20,0) --where character is a reference to the player's character, and CFrame.new() contains the desired position

6 comments

0

Doesn't work, you need to change the TORSO's Cframe.

0

What do you mean? It's worked for me before. Additionally, it teleports the camera instead of the torso. And when I say before, I mean this morning.

0

I tested it again, works just fine, so please remove your downvote.

0

Now where is your explanation? What is character? Is it a variable? Why do you have to do CFrame.new istead of Vector3.new?

0

He asked how he could move the player using CFrames, he didn't ask about CFrames, so stop being a devil's advocate and if you care so much do it yourself. Besides, I already said what character was.

0

SetPrimaryPartsCFrame is also CFrame. I would recommend Torso because the torso has all the welds in it.

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