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

can't randomly choose player?

Asked by
8muq 2
3 years ago

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

Log in to vote
0
Answered by 3 years ago

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

0
Using GetPlayers() is better since it only returns the player objects. Subsz 366 — 3y
0
but ofc you wont create an instance and parent it to players xd greatneil80 2647 — 3y
Ad
Log in to vote
0
Answered by
Subsz 366 Moderation Voter
3 years ago

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.

0
Thanks 8muq 2 — 3y

Answer this question