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