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

Getting 2 random players from a server?

	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

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

1 comment

0

doesnt work and is kind of confusing..

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