My script prints the table of all the players on a specific team and it prints like this:
But when I try to convert it to a string it comes up as something like “Table: abcg07899” or something.
Anyone able to offer support?
My script prints the table of all the players on a specific team and it prints like this:
But when I try to convert it to a string it comes up as something like “Table: abcg07899” or something.
Anyone able to offer support?
Can we see your script please?
local playersOnTeam = game:GetService("Teams")["Fighter"]:GetPlayers()
if #playersOnTeam == 1 then
for _, Player in pairs(playersOnTeam) do
print(playersOnTeam)
game.ReplicatedStorage.Remotes.Winner:FireAllClients(tostring(playersOnTeam))
end
end
That’s called a memory reference it’s a hexadecimal reference to the place where the table starts in memory. If you want to get all of the player’s names in a table, you can use something like this:
function getNamesOnTeam(players)
local names = {}
table.foreach(players, function(index, player)
table.insert(names, player.Name)
end)
return names
end
then you can use table.concat to convert the entire table to a string like so:
table.concat(names, " ")
Edit: Well it appears I was writing this before the other replies came in, so this reply isn’t really what you want. If you just want one player then you can just index the table with playersOnTeam[1]
and get the name
You can’t convert a table to a string. Are you trying to get the player who is in the team?
Yeah. If there’s one player left on the team it fires a remote event which makes a GUI appear with the player’s name
Just change the line above to the following:
game.ReplicatedStorage.Remotes.Winner:FireAllClients(Player.Name)
Making that the player’s name wouldn’t work. The player here is the player who just died. It checks if there’s only one person left on the team. And if there is, then it gets that player’s name.
I don’t think I understand what you mean I’m sorry. I gotta go but I can help in about an hour, good luck with your problem.
can’t you just
local playersOnTeam = game:GetService("Teams")["Fighter"]:GetPlayers()
if #playersOnTeam == 1 then
game.ReplicatedStorage.Remotes.Winner:FireAllClients(playersOnTeam[1].Name)
end