Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
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())

1 comment

0

Thank you sooo much i was so confused c:

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())

1 comment

0

l thank you ill look in to it!

This discussion is preserved as it was. New answers, comments, and votes are closed.