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

can't randomly choose player?

I have this script in SeverScriptService

local p = table()

for i, v in pairs
do
	game.Players:GetPlayers()
	table.insert(#p, v.Name)
end

print(#p)

The error in the output says "ServerScriptService.Script:1: attempt to call a table value"

2 answers

✓ Accepted answer

To get a random player you index a random number in the players service:

local Rando = game.Players:GetChildren()[math.random(1,#game.Players:GetChildren())]

returns the player not the character.

also remember,

local table = {} -- create a table

and

for i, v in pairs(list) do
	-- code
end

if this helps then upvote and click answer, k thx

2 comments

0

Using GetPlayers() is better since it only returns the player objects.

0

but ofc you wont create an instance and parent it to players xd

First of all, you're creating the table wrong. the way you create a table is,

local table = {}

Secondly, GetPlayers() already returns a table, so i don't see a use of doing that.

1 comment

0

Thanks

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