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

What is going wrong? (Picking random players)

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by
LostPast 253 Moderation Voter
7 years ago

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()
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. jimborimbo 94 — 7y
Ad

Answer this question