How to announce the winner of a round in a gui based on the highest leaderstat for that round

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    currently have 2 teams wound like the script to find the highest kills leaderstat then remote event a gui to announce a player as the winner ( highest kills )
  2. What is the issue? Include screenshots / videos if possible!
    can system to announce the teams has won but not the player

Just need help constructing a script to indentify the highest leader stat ( kills ) then string to a gui to announce the winner .thank you

fire the event to all clients and in the argument put the winner’s name and allow the gui to become visible with the winner’s name

Your easiest option is to loop through each player and compare their kills leaderstat to the current highest. Something like so would work:

local function getHighestKills()
	local highestKills, highestKiller = 0, nil
	
	for i, v in pairs(game.Players:GetPlayers()) do
		local kills = v.leaderstats.Kills.Value 
		if kills > highestKills then
			highestKills = kills
			highestKiller = v
		end
	end
	
	return highestKiller
end

Regarding sending that data to the client you can do by using :FireAllClients() with the player name passed. From there you can update the client’s TextLabel by using Format String like so:

TextLabel.Text = string.format("%s had the highest kills.", playerName)```
--or
TextLabel.Text = playerName.. " had the highest kills"

here is a demo place, it won’t be very efficient,
but it should make u understand how it would work.

oops , wrong place. That was for someone else

Hi thank you for your help.

Im still a bit lost on how they connected with each other the server loop and the text label ?

Also just to confirm with the sever loop i only need it to look at the leaderstat once to confirm the highest award the win then the leader stats reset as this functon is part of a large game loop do i remove the return to achieve this. thank you

you would have to loop because if u dont loop that means that one player that first won will keep showing

hi mate if you have an example place that would help alot thank you

I did but I gave the wrong file. I need to get the actual file, BRB

heres an example file.

demo.rbxl (40.2 KB)

2 Likes

Constantly asking for the information isn’t necessary as leaderstats can be read from the client too. The better way to go about things is to constantly check for updates of the values either with a loop or more preferably using .Changed() or:GetPropertyChangedSignal()

2 Likes

Adding onto this, completely forgot you could just use table.sort() and then get the first index.

1 Like

Hey mate thank you for the help i have adapted both your and adams demo file now it is all working thank you

Thank you for the demo mate i adapted it to the script and now it works perfectly

1 Like

No problem, enjoy.

This text will be blurred

1 Like