Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make all contents of :GetChildren go into one line?

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)

1 answer

✓ Accepted answer

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

1 comment

0

Alright, got it.

This discussion is preserved as it was. New answers, comments, and votes are closed.