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

Getting 2 random players from a server?

Asked by 9 years ago
    for _, players in pairs(game.Players:GetPlayers()) do
        local p1 = players[1] -- ERROR HERE
        local p2 = players[2]
        if p1.Parent and p2.Parent then
            statustag.Value = p1.Name .. " vs. " .. p2.Name
            Instance.new("StringValue", script.Dueling).Name = p1.Name
            Instance.new("StringValue", script.Dueling).Name = p2.Name

            p1:MoveTo(arena:WaitForChild("Spawn1").Position)
            p2:MoveTo(arena:WaitForChild("Spawn2").Position)
        end
    end

Output says 1 isn't part of players. The point of this script is to get all players in the servers, pick 2 of them and teleport them to the 'Spawns'. Anyone help?

1 answer

Log in to vote
0
Answered by 9 years ago

Made a script here which I haven't tested so I'm not 100% on whether it'll work.

Players = game.Players:GetChildren()

Amt = 0 for _, player in pairs(Players) do Amt = Amt+1 end

local p1 = Players[math.random(0,Amt)] repeat local p2 = Players[math.random(0,Amt)] until p2~=p1

0
doesnt work and is kind of confusing.. NinjoOnline 1146 — 9y
Ad

Answer this question