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

Getchildren is not a valid member of Players????

Asked by 8 years ago
local allPlayers = {}
for a,v in pairs(game.Players:Getchildren(2)) do 
        table.insert(allPlayers,v)
end
local plrAmount = game.Players.Numplayers
local val1 = math.random(plrAmount)
local val2 
repeat
    val2 = val2 - math.random(plrAmount)
    wait(20)
until val2 ~=val1
allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0)
allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)
math.randomseed(os.time())

it says Getchildren is not a valid member of Players (in output)

2 answers

Log in to vote
0
Answered by 8 years ago
local allPlayers = {}
for a,v in pairs(game.Players:GetChildren(2)) do -- Lua is case sensitive.
        table.insert(allPlayers,v)
end
local plrAmount = game.Players.Numplayers
local val1 = math.random(plrAmount)
local val2 
repeat
    val2 = val2 - math.random(plrAmount)
    wait(20)
until val2 ~=val1
allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0)
allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)
math.randomseed(os.time())

0
Thank you sooo much i was so confused c: berrythebetta 20 — 8y
Ad
Log in to vote
2
Answered by 8 years ago
local allPlayers = {}
for a,v in pairs(game.Players:GetChildren()) do    --two typos here
        table.insert(allPlayers,v)
end
local plrAmount = game.Players.Numplayers
local val1 = math.random(plrAmount)
local val2 
repeat
    val2 = val2 - math.random(plrAmount)
    wait(20)
until val2 ~=val1
allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0)
allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)
math.randomseed(os.time())

This is your script, there's easier ways of doing this. Instead of having a generic for loop search through a table of all the players and insert them all into another table. You can get rid of the whole generic loop.

local allPlayers = game.Players:GetChildren()

local plrAmount = game.Players.Numplayers
local val1 = math.random(plrAmount)
local val2 
repeat
    val2 = val2 - math.random(plrAmount)
    wait(20)
until val2 ~=val1
allPlayers[val1].Character.Torso.CFrame = CFrame.new(0,0,0)
allplayers[val2].Character.Torso.CFrame = CFrame.new(665.995,7.1,-115.005)
math.randomseed(os.time())

0
l thank you ill look in to it! berrythebetta 20 — 8y

Answer this question