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

What is going wrong? (Picking random players)

I am attempting to pick 2 different players, however it always gets stuck on the first one. If you guys could help that would be great. The function accounts for most of the game script, this is just a snippet of the larger function. players is defined out side of the large function in the game script.

players = game.Players:GetChildren()

function pick()
repeat
	local invisiblechoice1 = players[math.random(1, #players)] -- Whenever I test it always gets stuck here. What's the problem? I examined it on its own and it worked fine.
	game.Workspace.Inv1.Value = invisiblechoice1.Name
	invisiblechoice1.Inv = true -- these are unrelated to my question, they ARE valid values in the player
	invisiblechoice1.Invs = true
		local invisiblechoice2 = players[math.random(1, #players)]
	game.Workspace.Inv12.Value = invisiblechoice2.Name
	invisiblechoice2.Inv = true
	invisiblechoice2.Invs = true
	until invisiblechoice1 ~=  invisiblechoice2
end

pick()

If you could tell me what is going wrong (I have tested this same script in other situations multiple times with success) that would be appreciated. Thanks!

1 answer

The problem is with line 1 and 5. GetChildren() needs ()

local players = game.Players:GetChildren() --:GetChildren() needs ()

function pick()
repeat
    local invisiblechoice1 = players[math.random(1, #players)] -- Whenever I test it always gets stuck here. What's the problem? I examined it on its own and it worked fine.
    game.Workspace.Inv1.Value = invisiblechoice1.Name
    invisiblechoice1.Inv = true -- these are unrelated to my question, they ARE valid values in the player
    invisiblechoice1.Invs = true
        local invisiblechoice2 = players[math.random(1, #players)]
    game.Workspace.Inv12.Value = invisiblechoice2.Name
    invisiblechoice2.Inv = true
    invisiblechoice2.Invs = true
    until invisiblechoice1 ~=  invisiblechoice2
end

pick()

1 comment

0

That's not the problem. I manually typed it out in the question, but in my script GetChildren() has parentheses. It is something else.

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