Cant convert table to a string

Is there any way to convert an instance to a string ? The output tells me that i cant use concat because my table is an instance and i cant understand why

local standingPlayers = table.concat(playersInRound, ',')
			print(standingPlayers)

invalid value (Instance) at index 1 in table for 'concat'

1 Like

This error happen when you try to use table.concat on a table that contains Instances.

Instances cannot be concatenated directly.

You must get the desired information from the instances (for example here maybe the players name) and store it in strings table before using table.concat.

2 Likes

I just tried doing it but the game tells me that playersInRound.Name is nil

local PlayersInRoundName = {}
	
	table.insert(playersInRound.Name)
	
			local standingPlayers = table.concat(PlayersInRoundName, ',')
			print(standingPlayers)

Because it’s a table and you haven’t defined anything with the “name” key :sweat_smile:

What do you want do do?

Im trying to apply what you just told me but it seems that i did it wrong Im sorry i dont really have experience in tables, could you please show me an example of script describing what you are telling me or something that could help me to visualise what i have to do ?

Alright, if I stick to what the error says and the fact I still don’t know what you want to do. I think you should do like this:

local PlayersInRoundName = {}

for _, player in pairs(playersInRound) do -- I've use generic for loop but if it's an array you can also use numeric for loop
	table.insert(PlayersInRoundName, player.Name)
end

local standingPlayers = table.concat(PlayersInRoundName, ',')
print(standingPlayers)

Tell me if this still doesn’t work.

1 Like

It works thank so much !

message too short

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.