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

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

Asked by 4 years ago

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

Log in to vote
1
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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

0
Alright, got it. RyanTheLion911 195 — 4y
Ad

Answer this question