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

How can I get all players that aren't in a group and display them on a TextLabel?

Asked by 4 years ago

My issue: I can't seem to get this script to actually apply the unpacked table to the TextLabel at the end of the script. There are no warnings or errors in the output.

What it's supposed to do: This script is supposed to get all of the people who aren't in the group and display them on the InfoScreen

What I've tried: - I've put various prints throughout the script (beginning, allplayers before changes, allplayers after changes, and the end) and they all printed successfully - I have put an if statement in the end to check if the table was nil before actually applying it to the TextLabel

local Players = game:GetService("Players")

local text = script.Parent:WaitForChild("People").Text


Players.PlayerAdded:Connect(function(player)

    local allplayers = game.Players:GetChildren()
    print(unpack(allplayers))

    for i=1,#allplayers do
        if allplayers[i]:IsInGroup(1) then
            table.remove(allplayers,i)
        end
    end


    text = unpack(allplayers)


end)

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

unpack converts a table into a tuple. You would have to perform a loop and concatenate all the player's names together like so:

function PlayerTableToString(t)
    local string = ""
    for i,v in pairs(t)do
        string = string .. v.Name .. " " -- add the player's name to the string and leave a space for the next player's name. You might want to customize that to be an end line or something but that's up to you.
    end
    return string
end
Ad

Answer this question