I want to make a gui that broadcasts the message to everyone, but when i try to get the guy’s name that won, it doesnt let me
the getplayersingame() is a table yes
message:FireAllClients(getplayersingame() .. " won!")
I want to make a gui that broadcasts the message to everyone, but when i try to get the guy’s name that won, it doesnt let me
the getplayersingame() is a table yes
message:FireAllClients(getplayersingame() .. " won!")
you need to index it first
You are trying to reinvent the wheel… (I know that it pisses people off of me saying that 9949294th time but damn its true tho)
how would i index the getplayersingame function
You wouldn’t be indexing the function; You would be indexing the table that the function returns. If getplayersingame() returns a table of Player instances. For example:
local winners = getplayersingame()
local firstPlayer = winners[1]
Given you’re dealing with a table of Player instances (assuming they are all “winners”) you’ll likely want to iterate over the table, concatenating the DisplayName of each Player:
function concatenatePlayers(players)
if #players == 0 then
return "No one"
elseif #players == 1 then
return players[1].DisplayName
else
local playerString = "and " .. players[#players].DisplayName
for i = 1, #players - 1 do
playerString = players[i].DisplayName .. ", " .. playerString
end
return playerString
end
end
local winners = getplayersingame()
local winnerString = concatenatePlayers(winners)
message:FireAllClients(winnerString .. " won!")