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

Can you get all the players in a server script table?

Asked by
MattVSNNL 620 Moderation Voter
3 years ago
Edited 3 years ago

I'm making a murder mystery game and getting everyone that's not the murder of sheriff will be an innocent but I wanna get everyone from the table that's the innocent but I tried some scripts and it didn't work, Can anyone help me?

Here's the code thats the problem:

local innocent = playersAlive:GetChildren()
0
You only need to post the code you are having an issue with, could you cut this down to just the problem area? Benbebop 1049 — 3y
0
ok MattVSNNL 620 — 3y

2 answers

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

Problem

    local innocent = #playersAlive
Ad
Log in to vote
0
Answered by 3 years ago

I would recommend using "i,v in pairs"

for i, v in pairs(innocent)do
    --whatever you need to do
end

This will loop through the table and do what is inside the for loop for every member of the table. For instance this will print the name of every innocent player:

for i, v in pairs(innocent)do
    print(v.Name) -- v refers to the member of the table (i refers to the index or what loop you are currently on.)
end

I'm not very good with words, but I hope this helped. ;)

Answer this question