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

attempt to concatenate table with string?

hello! i am having trouble with a specific function. i've verified that everything else works, it's just this part of the minigame handler i am currently working on. i'm calling the function each time a player leaves or dies in a round, verifying that it updates.

"inround" is a table im adding and removing players to, in order to manage a round.

server script;

local win = repstr:WaitForChild("PlayerWin")

function findwin()
	if #inround == 1 then
	print(unpack(inround)) -- for checking
	win:FireAllClients(inround, 1)
	end
end

local script;

local hintbar = script.Parent.ScreenGui.TextLabel


game.ReplicatedStorage.PlayerWin.OnClientEvent:Connect(function(inround)
	hintbar.Text = inround.. " has won the round!"
end)

the error is on this line;

hintbar.Text = inround.. " has won the round!"

specifically, it says "attempt to concatenate table with string". any help would be greatly appreciated!

2 answers

✓ Accepted answer

The problem is, that inround value is a table. You have to convert it to a string. You can do this to fix the problem

inround[Player]
local hintbar = script.Parent.ScreenGui.TextLabel

game.ReplicatedStorage.PlayerWin.OnClientEvent:Connect(function(Player)
    hintbar.Text = (Player.." has won the round!")
end)

3 comments

0

tried applying the edits you did, it resorted to telling me about an "incorrect statement". is there any other way i can convert a table to a string?

0

Table[string]

0

after a bit of tinkering, i got your solution to work! thank you!

inround still remains an Array, you’re essentially trying to mend an Object to a string, which is causing controversy. To attain a properly extract and format a string of all the "contestants" within the array, you can use the table.concat() function, and pass the separation argument with a whitespace.

local Text = table.concat(Array, ' ').." has won the game!"

1 comment

0

ive now made those edits, but i've gotten another error which is "invalid value (userdata) at index 1 in table for 'concat'". the edited line now is "hintbar.Text = table.concat(inround, ' ').." has won the game!""

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