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

table.concat sticks strings together, how to fix?

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

✓ Accepted answer

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.

3 comments

0

The message stuff is experimental and was written only for example.

0

But did I answer your original question?

0

Yes, thanks, answer is accepted.

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