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

I want the game to get all children & book them in a var?

Asked by 10 years ago

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?

2 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
10 years ago
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
0
No explanations? HexC3D 830 — 10y
0
The only part he didn't do was MoveTo() and that's pretty self explanatory, once you look at the script. Azarth 3141 — 10y
Ad
Log in to vote
0
Answered by
war8989 35
10 years ago

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

Answer this question