So basically I want to turn a table into mulitple strings instead of 1. I tried using table.concat but that turns the table into 1 string. Which I don’t want it to do
Could you send your script that you tried using?
local players = {}
game.Players:GetPlayers(function(plr)
table.insert(players, plr)
end)
game.Players.PlayerAdded:Connect(function(plr)
table.insert(players, plr)
print(players)
plr.PlayerGui.BriefingGUI.Main.Player1 = (players[1])
--plr.PlayerGui.BriefingGUI.Main.Player2 = (players[2])
--plr.PlayerGui.BriefingGUI.Main.Player3 = (players[3])
--plr.PlayerGui.BriefingGUI.Main.Player4 = (players[4])
end)
You should make the Gui scripts as localscripts inside of StarterGui. It would be a lot more efficient.
PlayerAdded and GetPlayers don’t work on local scripts
What exactly are you trying to do? Is it just a single UI that you want to be visible when they join?
Basically there are 4 text labels (with a 4 player limit) and I want each players name listed on there.
In a localscript you could loop through the players in a in pairs loop and make the labels visible that way.
What do you mean by making the labels visible?
Sorry, not visible. I mean change the text to the player’s name, or whatever property you needed to change on them.
Here’s something I wrote on an unrelated post:
More can be found here:
pairs and iPairs
If you wanted each as separate variables you could do this:
local tbl = {'hi','bye','hello'}
local a,b,c = table.unpack(tbl)
print(a,b,c) -- hi, bye, hello
GetPlayers() does work in local scripts, I’m not sure who told you otherwise. You don’t need PlayerAdded as the local player can be fetched via “game.Players.LocalPlayer”.
I didn’t quite understand your request but I did try to do something about it, see if it helps.
local players = {}
game.Players:GetPlayers(function(plr)
table.insert(players, plr)
end)
game.Players.PlayerAdded:Connect(function(plr)
table.insert(players, plr)
print(players)
plr.PlayerGui.BriefingGUI.Main.Player1.Text = (players[1].Name)
--plr.PlayerGui.BriefingGUI.Main.Player2.Text = (players[2].Name)
--plr.PlayerGui.BriefingGUI.Main.Player3.Text = (players[3].Name)
--plr.PlayerGui.BriefingGUI.Main.Player4.Text = (players[4].Name)
--[[
You can also make this:
for i=1, #players do
plr.PlayerGui.BriefingGUI.Main["Player"..i].Text = (players[i].Name)
end
]]
end)
You probably don’t want to use server scripts and use localscripts, you can use remotevents on the client.
game.Players.PlayerAdded:Connect(function(plr)
table.insert(players, plr)
for i = 1, #players do
plr.PlayerGui.BriefingGUI.Main['Player' .. i].Text = (players[i])
end
end)
Can’t you just use the player’s Name property?
local players = game:GetService('Players')
for i,plr in ipairs(players:GetPlayers()) do
table.insert(players, plr.Name)
end
players.PlayerAdded:Connect(function(plr)
table.insert(players, plr.Name)
print(players)
plr.PlayerGui.BriefingGUI.Main.Player1 = (players[1])
end)