Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Trying to see who won a round. How do I do this?

I am developing my Shifting Factions game right now and I'm just getting to the end of the round script, but I have no idea how to check who has the most score out of all the players. (Note I haven't even tried because I have no clue how to do it) Here is the whole script:

while true do
	local players = game.Players:GetChildren()
	game.Workspace.Message.Text = "Waiting for another player"
	if #players < 2 then
		repeat
			wait(1)
			players = game.Players:GetChildren()
			print("Waiting for another player")
		until #players > 1
	end
	game.Workspace.Message.Text = "Intermission: 10 seconds"
	wait(3)
	game.Workspace.Message.Text = ""
	wait(10)
	local maps = game.ServerStorage.Maps:GetChildren()
	local map = maps:FindFirstChild("Map" .. math.random(1,#maps)):Clone()
	map.Parent = game.Workspace
	map.Name = "Map"
	game.Workspace.Message.Text = "Loaded Map: " .. map.MapName.Value
	wait(4)
	game.Workspace.Message.Text = "Game will begin soon"
	wait(1)
	local players = game.Players:GetChildren()
	local playerst = Instance.new("Team")
	playerst.TeamColor = BrickColor.new("Medium stone grey")
	playerst.AutoAssignable = true
	playerst.AutoColorCharacters = false
	playerst.Name = "Players"
	playerst.Parent = game.Teams
	local wantedt = Instance.new("Team")
	wantedt.TeamColor = BrickColor.new("Bright red")
	wantedt.AutoAssignable = false
	wantedt.Name = "Wanted"
	wantedt.Parent = game.Teams
	local innocentt = Instance.new("Team")
	innocentt.TeamColor = BrickColor.new("Bright blue")
	innocentt.AutoAssignable = false
	innocentt.Name = "Innocent"
	innocentt.Parent = game.Teams
	for i = 1,#players do
		players[i].TeamColor = BrickColor.new("Bright blue")
		players[i].Neutral = false
		local stat = Instance.new("IntValue")
		stat.Name = "Points"
		stat.Value = 0
	end
	local wanted = players[math.random(1,#players)]
	print("Wanted man is " .. wanted:GetFullName())
	wanted.TeamColor = BrickColor.new("Bright red")
	wanted.leaderstats.Points.Value = 10
	for i = 1,#players do
		local sword = game.ServerStorage.Sword:Clone()
		sword.Parent = players[i].StarterGear
		players[i]:LoadCharacter()
	end
	game.Workspace.InGame.Value = true
	repeat wait() until game.Workspace.GameTime.Minutes.Value == 0 and game.Workspace.GameTime.Seconds.Value == 0
	local players = game.Players:GetChildren()
	game.Workspace.InGame.Value = false
	game.Workspace.Message = " won!"
end

1 answer

maxplayerptsfound =  0
player = nil
for i= 1 ,  #players do 
 if (players[i].Stats.Value  > maxplayerptsfound ) do 
     maxplayerptsfound  = players[i].Stats.Value
end
player = players[i]
end
if player.Stats.Value == maxplayerptsfound do 
return player
end 

This discussion is preserved as it was. New answers, comments, and votes are closed.