Does anyone know how i can show whoever has the highest value on a textlabel worldwide?

effectively what my script does is the player that has the highest amount of deaths in the server is displayed on a surface gui
image
it works perfectly, except one thing
its not very useful seeing as there are leaderstats in the game so you can already see who has the highest amount of deaths
image

im not sure how to make it find who has the highest deaths worldwide, whether the player is online or not
heres my script (i did get a bit of assist from the roblox ai)

local Players = game:GetService("Players")
local frame = script.Parent

local function getPlayerWithHighestDeaths()
	local highestDeaths = 0
	local playerWithHighestDeaths

	for _, player in ipairs(Players:GetPlayers()) do
		if player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Deaths") then
			local deaths = player.leaderstats.Deaths.Value
			if deaths > highestDeaths then
				highestDeaths = deaths
				playerWithHighestDeaths = player
			end
		end
	end

	return playerWithHighestDeaths
end

local function setUserThumbnail(imageLabel, userId)
	local thumbType = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size420x420
	local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)

	
	imageLabel.Image = isReady and content or "rbxassetid://0"
end

local function updateFrame()
	local playerWithHighestDeaths = getPlayerWithHighestDeaths()

	if playerWithHighestDeaths then
		
		frame.PlrName.Text = playerWithHighestDeaths.Name

		
		frame.Deaths.Text = "Deaths: " .. playerWithHighestDeaths.leaderstats.Deaths.Value

		
		local character = playerWithHighestDeaths.Character
		if character then
			local head = character:FindFirstChild("Head")
			if head then
				local imageLabel = frame.Img
				setUserThumbnail(imageLabel, playerWithHighestDeaths.UserId)
				return
			end
		end
	end

	frame.Img.Image = "rbxassetid://0"
	frame.PlrName.Text = "No player found"
	frame.Deaths.Text = "Deaths: N/A"
end

updateFrame()

local function updatePeriodically()
	while true do
		updateFrame()
		wait(10)
	end
end

local function onPlayerAdded(player)
	updateFrame()
end

Players.PlayerAdded:Connect(onPlayerAdded)

coroutine.wrap(updatePeriodically)()

if anyone can gimmie a hand it will really help

Check this video out

OrderDataStore is your friend :saluting_face:

alright ill check this video out

can you kindly explain please :smiley:

Thats exactly what the video I linked is about, it shows you how to setup an ordered datastore for your game!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.