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

table.concat sticks strings together, how to fix?

Asked by
zuup123 99
5 years ago

I was making my game and added a winners table, when the game displays text with winners it sticks names together.

Here's the part of the script:

function changeMessage(text)
    local message = workspace:FindFirstChild("GameHint")

    if message then
        message.Text = text
    elseif not message then
        createMessage()
    end
end

for i,player in pairs(game.Teams.Survivors:GetPlayers()) do
    if game.Teams.Survivors:GetPlayers() then
        table.insert(winners, player.Name)
        end
end

changeMessage("Survived: ".. table.concat(winners))

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I'm assuming you want a delimiter; a separator for each name.

table.concat's second argument! It is expected to be a string, and it will just separate each table element with the specified delimiter

local function changeMessage(text)
    local message = workspace:FindFirstChild("GameHint") -- recommend you change this. messages and hints are deprecated! 

    if message then
        message.Text = text
    else
        createMessage()
    end
end

for _, player in pairs(game.Teams.Survivors:GetPlayers()) do
        table.insert(winners, player.Name)
end

changeMessage("Survived: ".. table.concat(winners, ", ")

So say the table was {"Player1", "Player2"}, the string would look like Player1, Player2.

I removed some unnecessary stuff too.

0
The message stuff is experimental and was written only for example. zuup123 99 — 5y
0
But did I answer your original question? User#24403 69 — 5y
0
Yes, thanks, answer is accepted. zuup123 99 — 5y
Ad

Answer this question