I'm not sure if I have any errors in this as I can't access studio right now, so I'm simply asking if someone could proof read it. The end goal for this script is to wait for the round to end, and when it does I want it to change the string value (Status) to the winners. The problem that I had to work around is that I want it to say "and x" when the last player name is being displayed, but I didn't want it to say and in between every player (example: a and b and c).
What I want it to look like is this: "The winners are: player 1, player 2, player 3, and player 4
--// Variables \\-- Status = game.ServerStorage.Status --// Main Script \\-- game.ReplicatedStorage.RoundEnding.OnServerEvent:Connect(function(Reason) if Reason == “RunnersWon” then for i, player in pairs(game.Players:GetPlayers()) do wait(1.5) if player.Dead.Value ~= true and player.Role.Value ~= nil then player.leaderstats.Points.Value = player.leaderstats.Points.Value+15 if i == 1 then Status.Value = “The winners are: “ player.Name.. “,” elseif i == NumPlayers then Status.Value = Status.Value.. “ and ”.. player.Name else Status.Value = Status.Value.. player.Name.. “,” end end end end end)
You need to add winners to a table, detect if table is not nil and use table.concat.
Wiki pages:
Here is a example:
-- winners table local winners = {} -- Add players for i,player in pairs(game.Players:GetPlayers()) do if player.Dead.Value ~= true and player.Role.Value ~= nil then table.insert(winners,v.Name) end end wait() -- detect if table is nil or not if winners[1] ~= nil then print("Winners: " .. table.concat(winners, ", ")) -- Print winners else print("No winners") end
here is your fixed script:
--// Variables \\-- local Status = game.ServerStorage.Status local Winners = {} --// Main Script \\-- game.ReplicatedStorage.RoundEnding.OnServerEvent:Connect(function(Reason) if Reason == "RunnersWon" then for i, player in pairs(game.Players:GetPlayers()) do if player.Dead.Value ~= true and player.Role.Value ~= nil then player.leaderstats.Points.Value = player.leaderstats.Points.Value+15 table.insert(Winners,player.Name) end end wait() if Winners[1] ~= nil then Status.Value = "The winners are: " .. table.concat(Winners, ", ") else Status.Value = "No winners found!" end end end)
Hope it helped :)