Top Player Global Leaderboard Overhead GUI Change Help

So the title is mainly what I’m trying to do. If I can achieve or figure out the way to get the player from the global leaderboard check their value or I guess you can say rank and then change a OverheadGUI text that is parented to their head.

Here is the script for the OverheadGUI that works -

--[[
	@author TwinPlayzDev_YT
	@credit Neutron_Flow for the help
	@since 1/28/2021
	This script will give anyone who owns gamepasses or is in groups, a special overhead tag
	that is displayed over peoples heads. Please watch my tutorial on youtube on how to use.
	Place this script in ServerScriptService.
--]]


--[ SERVICES ]--

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

--[ LOCALS ]--

local VIPOverheadGui = ReplicatedStorage:WaitForChild("VIPOverheadGui") -- GRABBING THE OVERHEAD GUI's
local OverheadGui = ReplicatedStorage:WaitForChild("OverheadGui")
local OwnerOverheadGui = ReplicatedStorage:WaitForChild("OwnerOverheadGui")
local DonatorOverheadGui = ReplicatedStorage:WaitForChild("DonatorOverheadGui")
local GamepassId = 13913938 -- GAMEPASS ID GOES HERE
local Configuration = game.Workspace.Boards.R15Loader.Configuration -- Finding Configuration
local DONATOR_ID = Configuration.userId -- Making Donator ID

--[ FUNCTIONS ]--

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		-- These variables are used regardless of whether the user owns the gamepass or not
		-- so we can define them outside the if statement
		local Humanoid = Character:WaitForChild("Humanoid")
		local Head = Character:WaitForChild("Head")
		
		-- Again, this happens regardless of the if statement
		Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		
		-- Owner Name
		if Player.Name == "TwinPlayzDev_YT" then
			local CloneGuiOwner = OwnerOverheadGui:Clone()
			CloneGuiOwner.Username.Text = Player.Name
			CloneGuiOwner.Name = "OverheadGui"
			CloneGuiOwner.Parent = Head
			CloneGuiOwner.Rank.Text = "VIBE CREATOR"
		-- TOP DONATOR
		elseif Player.UserId == DONATOR_ID.Value then
			local DonatorCloneGui = DonatorOverheadGui:Clone()
			DonatorCloneGui.Username.Text = Player.Name
			DonatorCloneGui.Name = "OverheadGui"
			DonatorCloneGui.Parent = Head
		-- VIP / MORE RANKS
		elseif MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId) then
			local Role = "VIP"
			local CloneGuiVIP = VIPOverheadGui:Clone()
			CloneGuiVIP.Username.Text = Player.Name
			CloneGuiVIP.Rank.Text = Role
			CloneGuiVIP.Name = "OverheadGui"
			CloneGuiVIP.Parent = Head
			local character = game.Workspace:WaitForChild(Player.Name)
		else -- Different Ranks
			local leaderstats =Player:WaitForChild("leaderstats") -- getting there leaderstats
			local Minutes = leaderstats.Minutes.Value -- getting there minutes
			local CloneGui = OverheadGui:Clone()
			CloneGui.Username.Text = Player.Name
			CloneGui.Name = "OverheadGui"
			CloneGui.Parent = Head
			if Player.leaderstats.Minutes.Value >= 10000 then -- Over 10000 Minute Rank
				CloneGui.Rank.Text = "Vibe Insanity"
				CloneGui.Rank.TextColor3 = Color3.new(1, 0.917647, 0.00784314)
			elseif Player.leaderstats.Minutes.Value >= 5000 then -- Over 5000 Minute Rank
				CloneGui.Rank.Text = "Vibe Maniac"
				CloneGui.Rank.TextColor3 = Color3.new(1, 0, 0)
			elseif Player.leaderstats.Minutes.Value >= 1000 then -- Over 1000 Minute Rank
				CloneGui.Rank.Text = "Vibe God"
				CloneGui.Rank.TextColor3 = Color3.new(1, 0.666667, 0.133333)
			else  -- DEFAULT RANK
				CloneGui.Rank.Text = "Vibe Newbie"
			end
		end
	end)
end)

Here is the script for the MODIFIED VERISON of this global leaderboard i’ve been using -

-- [ SETTINGS ] --

local StatsName = "Minutes" -- Your stats name
local MaxItems = 100 -- Max number of items to be displayed on the leaderboard
local MinValueDisplay = 1 -- Any numbers lower than this will be excluded
local MaxValueDisplay = 10e15 -- (10 ^ 15) Any numbers higher than this will be excluded
local UpdateEvery = 80 -- (in seconds) How often the leaderboard has to update

-- [ END SETTINGS ] --


-- Don't edit if you don't know what you're doing --

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetOrderedDataStore("GlobalLeaderboard_" .. StatsName)
local SurfaceGui = script.Parent
local Sample = script.Sample
local List = SurfaceGui.Frame.List
local ItemsFrame = List.ListContent.Items


-- ADDED LIST FOR RANKS --
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		
		local Humanoid = Character:WaitForChild("Humanoid")
		local Head = Character:WaitForChild("Head")
		local OverheadGui = Head:WaitForChild("OverheadGui") --overhead
		
		local function GetItems()
			local Data = DataStore:GetSortedAsync(false, MaxItems, MinValueDisplay, MaxValueDisplay)
			local TopPage = Data:GetCurrentPage()

			ItemsFrame.Nothing.Visible = #TopPage == 0 and true or false

			for i, v in ipairs(TopPage) do
				local UserId = v.key
				local Value = v.value
				local Username = "[Not Available]"
				local Color = Color3.fromRGB(38, 50, 56)

				local Success, Error = pcall(function()
					Username = game.Players:GetNameFromUserIdAsync(UserId)
				end)

				if i == 1 then
					OverheadGui.Rank.Text = "Minute Champion"
					Color = Color3.fromRGB(255, 215, 0)
					OverheadGui.Rank.TextColor3 = Color
				elseif i == 2 then
					OverheadGui.Rank.Text = "Minute God"
					Color = Color3.fromRGB(192, 192, 192)
					OverheadGui.Rank.TextColor3 = Color
				elseif i == 3 then
					OverheadGui.Rank.Text = "Minute Legend"
					Color = Color3.fromRGB(205, 127, 50)
					OverheadGui.Rank.TextColor3 = Color
				end

				local Item = Sample:Clone()
				Item.Name = Username
				Item.LayoutOrder = i
				Item.Values.Number.TextColor3 = Color
				Item.Values.Number.Text = i
				Item.Values.Username.Text = Username
				Item.Values.Value.Text = Value
				Item.Parent = ItemsFrame
			end
		end
		
		while true do
			for i, v in pairs(game.Players:GetPlayers()) do
				local Stats = v.leaderstats:WaitForChild(StatsName).Value
				if Stats then
					pcall(function()
						DataStore:UpdateAsync(v.UserId, function(Value)
							return tonumber(Stats)
						end)
					end)
				end
			end

			for i, v in pairs(ItemsFrame:GetChildren()) do
				if v:IsA("ImageLabel") then
					v:Destroy()
				end
			end

			GetItems()

			wait()
			SurfaceGui.Heading.Heading.Text = StatsName .. " Leaderboard"
			List.ListContent.GuideTopBar.Value.Text = StatsName
			List.CanvasSize = UDim2.new(0, 0, 0, ItemsFrame.UIListLayout.AbsoluteContentSize.Y + 35)
			wait(UpdateEvery)
		end
		
		
	end)
end)

I tried doing something where I will grab the players overhead when they join and still have this leaderboard work.
I was looking at the part -

if i == 1 then
					OverheadGui.Rank.Text = "Minute Champion"
					Color = Color3.fromRGB(255, 215, 0)
					OverheadGui.Rank.TextColor3 = Color
				elseif i == 2 then
					OverheadGui.Rank.Text = "Minute God"
					Color = Color3.fromRGB(192, 192, 192)
					OverheadGui.Rank.TextColor3 = Color
				elseif i == 3 then
					OverheadGui.Rank.Text = "Minute Legend"
					Color = Color3.fromRGB(205, 127, 50)
					OverheadGui.Rank.TextColor3 = Color
				end

Which was originally in my thought the rank holder. So If someone was ranked 1st,2nd,or 3rd. It would change their color to be that color gold,bronze,silver.

Im wondering, do I need to add the way of finding the player user id? Maybe just in all leaving the leaderboard the same and working on it in the other first script? Trying to add events that could be fired if i==1?

ATM that MODIFIED SCRIPT, is making it so when I spawn in its changing my Overhead.Text to that i==1 and im guessing because im only checking if i==1 and not if player.UserID = player.UserID.Key ?

If anyone has any idea please let me know.
Sorry for making this super long. Just very confused.

4 Likes

You see, you already did a global leaderboard but why would you go with the leaderboard itself? So, for example you have a leaderboard minute script and for a overhead rank GUI, you would have “MinutesR” which would Stannd for “Minutes Rank”

You can make a script under the MinuteRank text.
you would also need a group rank script/name

so for the main part, you have ifPlayerIsInGroup(randomidhere) then script.Parent.GroupRank = rankid (something like that)

For the minute script you will need to specify if you would like to manually make it again or update it all with the leaderboard.

so something like that.

For your answer to be updating with your leaderboard, I don’t think it can well it would be difficult so just for the playerId.

I am confused with your script so forgive me if this isn’t exactly what you want.

I subscribed to you on YouTube for a while, I asked for this script but know I learned how to kind of work it out, hopefully you can get this!

1 Like

why r u using the leaderboard scripts in the CharacterAdded function?? xd

Sort of confused, but ill check it out. Thankyou for your help. I might comback later and see, becuase im guessing you are saying

make anotehr script under a certain frame or wtv to check if playerid = that id.

Thanks for the help mr, Bulgari. I would love to see you try this out? And no it shouldn’t matter Character Added is correct.

It matters, you can’t really put the leaderboard scripts in the CharacterAdded function.