I'm making a simple script in which when a ClickDetector is activated it will loop through all of the players in the game at the current time and paste them onto a GUI TextButton. However, it only is printing the first name on the list which when testing on studio is simply just 'Player1'. How would I make it so the names are listed in a row, such as: 'Player 1 Player 2 Player 3'. I have done this previously but can't recall how I did it. Here is the code that I have got so far:
local player = game.Players game.Workspace.Bowl.ClickDetector.MouseClick:Connect(function() for i,v in pairs(player:GetChildren()) do script.Parent.playerList.Text = v.Name end end)
You are currently looping through the players and changing the text to one players name, than changing it the next players name, etc.
make a string and add each players name to it then make that the text.
local player = game.Players game.Workspace.Bowl.ClickDetector.MouseClick:Connect(function() local playersString = "" for i,v in pairs(player:GetChildren()) do playersString = playersString .. " " .. v.Name end script.Parent.playerList.Text = playersString end)
Excuse formatting I'm on mobile