Convert table value to string

Trying to convert tables value to string.

Code:

local players = {game.Players:GetPlayers()}
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:Connect(function(died)
			if table.find(players, player) then
				table.remove(players, player)
			end
		end)
	end)
end)
print(players)
repeat
	wait(1)
	StartRound()	
until #players == 1
changeColourText(players[1].." has won the game!")
table.clear(players)
1 Like

2 Things,

table.remove expects an index to remove, you can put the result of table.find(players, player) in a variable, check if it’s not nil and if isn’t nil, use the result to remove from the table

And since you’re using player instance, you can just use players[1].Name to get the name of the player who won

Not sure if anything will be affected byt it but

local players = {game.Players:GetPlayers()}

You don’t need to encase it, GetPlayers() returns a table

local players = game.Players:GetPlayers()
1 Like

image

Sorry to disturb, but the name fix did not work.

Any other solutions to this?

1 Like

Lemme check real quick lol. gimme a sec

Do

changeColourText(players[1].Name.." has won the game!")

So you get the name as a string.

1 Like

Thats exactly what I wrote. Still doesnt work.

Send your updated script here then.

1 Like

Printing

players[1].Name

comes out as a nil value.

local players = {game.Players:GetPlayers()}
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		char.Humanoid.Died:Connect(function(died)
			local find = table.find(players, player)
			if find then
				table.remove(players, find)
			end
		end)
	end)
end)
print(players)
repeat
	wait(1)
	StartRound()	
until #players == 1
print (players[1].Name)
changeColourText(players[1].Name.." has won the game!")
table.clear(players)



end
1 Like

Then the table item obviously doesn’t exist.
If that is your script and the local players = game.Players:GetPlayers() isn’t inside a function the it will run when the game starts before the player joins, therefor making the table empty.

The table is showing data though. Let me send a screenshot.

1 Like
local players = {game.Players:GetPlayers()}

Because you put the brackets there twice you are making a meta table. Someone already told you to change that to

local players = game.Players:GetPlayers()

.

Ok thanks! :smiley: Ill try it rn.

1 Like

Also sorry if I came across rude lol.

local LastPlayer = table.concat(players, "")

Should return a string.

1 Like

That is unneeded if instances are contained in that table, which there are. All @OP needs to do is just get the name from that player via players[1].Name

1 Like

Just read back the comments. I found the solution. Thank you!

Would just like to point out:

local players = {game.Players:GetPlayers()}

is not a metatable, it’s a nested table (a table within a table)

Metatables are very different, there’s a few forum posts you can search for which can explain the basics (and the more advanced stuff)

1 Like

Yup I fixed that in later posts.

Thanks for the clarification lol.

1 Like