Which is better [ASK]

So let’s say I wanna combine lists of strings in a table,
Is it better using message = table.concat(Args, 1, #Args)
or using for loops like

for i, arg in ipairs(Args) do
message = message.." "..arg
end

table.concat by far as it’s a built in function. keep in mind that the second argument is the separator, which defaults to an empty string. To replicate your for loop example use

message = table.concat(Args, " ")

I would further recommend against using .. successively in big long loops, every time it goes through the loop it will allocate a new string and this old unused memory will sit around until the garbage collector kicks in.

For example

local args: {string|number} = {
	"My", "big", "long", "wordy", "array", "ends here!"
}

local message: string = ""
for _, value in ipairs(args) do
	message = message .. " " .. value
end

will end up storing all of these strings in memory:

" My"
" My big"
" My big long"
" My big long wordy"
" My big long wordy array"
" My big long wordy array ends here!" -- this is the only one kept by message
2 Likes

Like what @gertkeno said, use table.concat. Roblox functions are generally always faster no matter how much optimization you put into it. There’s no point reinventing the wheel when a solution already exists.