Why can't i Select a random player to teleport?

  1. What do you want to achieve? Choosing a random player to teleport to specific Position.

  2. What is the issue?
    Screenshot 2025-03-05 144031

  3. What solutions have you tried so far? Tried to search up on the internet but couldn’t find a related topic.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Players = game:GetService("Players")

local IntermissionTime = 10
local RoundTime = 10

local MinPlayers = 1

local function tpPlayers()
	local players = Players:GetPlayers()

	local pickedPlayer = Players[math.random(#Players)]
	
	for i, player in players do
		if player == pickedPlayer then
			player.Character.HumanoidRootPart.CFrame = game.Workspace.AttackerPos.CFrame
		else
			player.Character.HumanoidRootPart.Position = Vector3.new(math.random(-14, 14), 166.5, math.random(120, 148))
		end
	end
end

(This is not the whole script only the part where it teleport the players).

Thank you for your time!

You used #Players with a capital P, thats a reference to game.Players

Replace it with #players

Still gives the same error?
Were you talking about this “p”

local function tpPlayers()
	local players = Players:GetPlayers()

	local pickedPlayer = players[math.random(#Players)] --Here is the line i changed
	
	for i, player in players do
		if player == pickedPlayer then
			player.Character.HumanoidRootPart.CFrame = game.Workspace.AttackerPos.CFrame
		else
			player.Character.HumanoidRootPart.Position = Vector3.new(math.random(-14, 14), 166.5, math.random(120, 148))
		end
	end
end

Oh sorry only seen it now you mean #players

1 Like

It atually still didnt work
Screenshot 2025-03-05 150038

oh my bad!
i think players[math.random(#players)] should work. (both lowercase)

1 Like

It attually worked! Thanks DoorsPro_Bacon!

1 Like