I want the game to get all the children players and book them in a variable then teleport them and this is the script:
local ppirates = game.Players:GetChildren() for x=1, #ppirates do if ppirates[x] ~= nil then if ppirates[x] ~= nil then if ppirates[x].Character:findFirstChild("Torso") ~= nil then ppirates[x].Character.Torso.CFrame = CFrame.new(pos+Vector3.new(243,1.5,-225.4))
The problem is that it does not work. Why? How can I fix it?
local players = game.Players:GetPlayers() for i,v in pairs(players) do if v.Character then v.Character:MoveTo(Vector3.new(243,1.5,-225.4)) end end
On line 6 you are calling a variable pos
, but from what I see, that variable is not declared, I presume that you are trying to add to the the player's position, which you don't need to do. You can just do this:
ppirates[x].Character:MoveTo(Vector3.new(243, 1.5, -225.4))
That'll teleport the player to those coordinates. About booking the players into a variable, you can declare a table and insert each player into that table, but you'll have to modify the table each time a player disconnects and each time a player joins the game, or the table will be out-of-date.
Or a simpler way:
players = game.Players:GetPlayers() for _, v in pairs(players) do if(v.Character) then v.Character:MoveTo(Vector3.new(243, 1.5, -225.4)) end end