local RS = game:GetService("ReplicatedStorage")
local Text = script.Parent.Text
RS.LavaEventServer.OnServerEvent:Connect(function()
for _,plr in pairs(game.Teams.Player:GetPlayers()) do
end
end)
I have this block of code, and inside every time the for loop runs, it gets the information of a player. Then I want it to take that information and add it to the existing text that is part of the GUI.
Example of outcome:
Winners: Jacob, Charlie, Izzabella, Jeremy
local RS = game:GetService("ReplicatedStorage")
local Text = script.Parent.Text
RS.LavaEventServer.OnServerEvent:Connect(function()
Text = "Winners: "
if #game.Teams.Player:GetPlayers() > 0 then
for _,plr in pairs(game.Teams.Player:GetPlayers()) do
if _ < #game.Teams.Player:GetPlayers() then
Text = str..plr.Name..", "
else
Text = str..plr.Name
end
end
else
Text = "Nobody won!"
end
end)
local RS = game:GetService("ReplicatedStorage")
local Text = script.Parent.Text
Text = "Winners: "
RS.LavaEventServer.OnServerEvent:Connect(function()
for _,plr in pairs(game.Teams.Player:GetPlayers()) do
Text = Text..plr.Name
end
end)
Something like that will work, if you use "text".. then you can concatenate with other text, sort of like âaddingâ text onto the end.
The post above has better code though, do if youâre gonna copy either then use his.
Thinking this will work you need to set the text in the text label after running through players
local RS = game:GetService("ReplicatedStorage")
--local Text = script.Parent.Text -- if you don't need the current text from this label then you don't need this line
local Text = "Winners: " -- if no text retrieved from above just set this to start
RS.LavaEventServer.OnServerEvent:Connect(function()
for i,plr in ipairs(game.Teams.Player:GetPlayers()) do
comma = i == 1 and '' or ', '
Text = Text .. comma .. plr.Name
end
script.Parent.Text = Text -- set the text after concating it
end)
After tinkering with the code for a while and modifying it to work with the other parts of my game, I have ended up with this:
local RS = game:GetService("ReplicatedStorage")
local TextLabelText = script.Parent.Text
RS.LavaEventClient.OnClientEvent:Connect(function()
local Text = "Winners: "
for i,plr in ipairs(game.Teams.Player:GetPlayers()) do
print(plr)
Text = Text..plr.Name..", "
end
script.Parent.Text = Text
game.ReplicatedStorage.WinnerListEvent:FireServer()
wait(4)
script.Parent.Text = " "
end)