I have a problem, I would like to get the play name from a list and put it in a variable (string).
local gameresults = "oneplayeralive" if #activecontestants == 1 then partforwinner.CanCollide = true for _, player in pairs(activecontestants) do if player then local playername = player:GetFullName() event:FireAllClients(gameresults, playername) end end else gameresults = "nowinner" end
And to put it in a gui :
event.OnClientEvent:connect(function(...) local tuple = ... if tuple == "oneplayeralive" then resultsannonce.Text = "The winner is" winnerannonce.Text = tuple[2] else resultsannonce.Text = "No winner" winnerannonce.Visible = false end
But, when I test, it's send me an error because "tuple[2]" is not a string.
If someone could help me, it's could be great, thanks you.
(sorry for the bad english, i'm french)
The reason your program errored was because you did not put brackets { } around the TWO arguments you had for your tuple in the FireAllClients
method. While I simplified your code to not have that be necessary, it's important to recognize that FireAllClients
only takes one argument, so put all your parameters in a table. The code below works the same way your old code did functionality wise; I assume that the if-statement is inside some sort of function or other callable system on your server.
You had a second problem where if there was no winner, the clients wouldn't have been informed. I made it FireAllClients
regardless of the result.
Server Code
local player = nil if #activecontestants == 1 then partforwinner.CanCollide = true player = activecontestants[1] end event:FireAllClients(player)
Client Code
event.OnClientEvent:connect(function(...) local tuple = ... if tuple then resultsannonce.Text = "The winner is" winnerannonce.Text = tuple.Name else resultsannonce.Text = "No winner" winnerannonce.Visible = false end end)