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

How to change a character's position?

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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)
0
Question, Won't the first thing , I mena CFrame move the player named Player? brokenrares 48 — 9y
0
brokenrares of course, It's just for an example though. EzraNehemiah_TF2 3552 — 9y
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 vixoau 0 — 3y
Ad
Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

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.

0
Yeah I'd like to know how to do that with CFrame please? brokenrares 48 — 9y
0
Just set the CFrame of the torso. character.Torso.CFrame = CFrame.new(0, 0, 0). Also, look up CFrame on the wiki. Perci1 4988 — 9y
Log in to vote
-1
Answered by 9 years ago
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
0
Doesn't work, you need to change the TORSO's Cframe. EzraNehemiah_TF2 3552 — 9y
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. aquathorn321 858 — 9y
0
I tested it again, works just fine, so please remove your downvote. aquathorn321 858 — 9y
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? EzraNehemiah_TF2 3552 — 9y
View all comments (2 more)
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. aquathorn321 858 — 9y
0
SetPrimaryPartsCFrame is also CFrame. I would recommend Torso because the torso has all the welds in it. EzraNehemiah_TF2 3552 — 9y

Answer this question