Help make random Player picker

Hello, im trying to make it where someone random gets picked in the lobby to be the killer but I don’t know how to do it, any help?

9 Likes

Reference all your players using:
local players = game:GetService("Players"):GetPlayers().
Then you can pick one at random using:
local pickedPlayer = players[math.random(1, #players)].
This picks a random number between 1 and the total number of players, then uses it as an index to grab a player from the table of players you got with the previous line.

16 Likes

Why greater than or equal to 10? No specification about that

1 Like

Thanks

The Players.Value == 10 was remade to #(Players:GetPlayers()) >= 10)

1 Like

What are you talking about there wasn’t any script provided?

1 Like
-- Use GetService, as it is canonical for fetching services!
local Players = game:GetService("Players"):GetPlayers()

local randomPlayer

if #Players > 0 then
    randomPlayer = Players[math.random(#Players)]
end

this works but could you help with 1 more thing? i need the Monster to teleport to a Block and the people who arent the monsters to teleport to a different Part? i got the Monster teleporting to a block but not the other

function PickAndTeleport()
	local players = game:GetService("Players"):GetPlayers()
	local pickedPlayer = players[math.random(1, #players)]
	
		pickedPlayer.Character.HumanoidRootPart.CFrame = game.Workspace.TeleportMonster.CFrame
end

You could iterate through all players and move them all according to who is the monster like this:

for i, player in pairs(players) do--Loop through every player
	if player == pickedPlayer then--If they are the monster, teleport them to the monster spot...
		player.Character.HumanoidRootPart.CFrame = game.Workspace.TeleportMonster.CFrame
	else--Otherwise, send them to somewhere else...
		player.Character.HumanoidRootPart.CFrame = --your other spawn location
	end
end
1 Like

thanks for the help it works… 30 1characters1

1 Like