Points/Leveling System Overhead GUI [Module Script or Math?]

Hello! I was curious how I could possibly going about making a ranking ‘leveling’ system for an Overhead Gui on mine.

Basically:

The player has a Star with a ‘Level’ textlabel that needs to be changed based on the leaderstat:

	local Points = Player.leaderstats.Points

I thought about doing this at first:

Points.Changed:Connect(function()
			
		if Points.Value >= 5000 then 
				
			elseif Points.Value >= 5000 then

			elseif Points.Value >= 4000 then 

			elseif Points.Value >= 3000 then

			etc...
				
		end
			
end)

But I don’t like how it’s very crowded in the main script. So I though maybe:


then:

local module = {}

module.PointsRankings = {
	
	["100"] = {
		Points = 100,
		Level = 5,
	},
	
	["75"] = {
		Points = 75,
		Level = 1,
	},
	
}

return module

Is this simpler? I’m curious how I could go about even possibly with maybe a math function, maybe to check if the points are equal to a certain amount or how much it increments by then it would increase the Level by “1” or “2” lets say.

If not, how can I make a FOR LOOP, to check inside this module script, how much POINTS the player has/changed value, then checking the module script to see which amount equals inside, and assigning that 'Level" to the TextLabel.

Let me know! I believe it may be best to make a For Loop and check the module script.

Found a fix!

--[ SERVICES ]--

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

--[ OVERHEAD LOCALS ]--

local OverheadGUIs = ReplicatedStorage:WaitForChild("OverheadGUIs")
local OverheadGui = OverheadGUIs:WaitForChild("OverheadGui")

local AssetConfig = require(ReplicatedStorage.AssetConfig)
local GroupId = AssetConfig.Group.GroupID

-- Require the module script
local PointsModule = require(script.Parent.Points)

--[ MAIN FUNCTION ]--

Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAppearanceLoaded:Connect(function(Character)
        local Humanoid = Character:WaitForChild("Humanoid")
        local Head = Character:WaitForChild("Head")
        local Points = Player.leaderstats.Points

        Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

        local CloneGui = OverheadGui:Clone()
        local StarIcon = CloneGui.Star
        local StarLevel = StarIcon.Level
        local RankLabel = CloneGui.Rank

        -- Set initial text label values
        RankLabel.Text = "Guest"
        StarLevel.Text = "1" -- Default level

        CloneGui.Name = "OverheadGui"
        CloneGui.Parent = Head

        -- Function to update level based on points
        local function UpdateLevel()
            for points, data in pairs(PointsModule.PointsRankings) do
                if Points.Value >= data.Points then
                    StarLevel.Text = tostring(data.Level)
                end
            end
        end

        -- Call the update function initially
        UpdateLevel()

        -- Listen to changes in points
        Points.Changed:Connect(function()
            UpdateLevel()
        end)

        -- Check group rank
        local Role = "Guest"
        pcall(function()
            local Rank = Player:GetRankInGroup(GroupId)
            Role = Player:GetRoleInGroup(GroupId)
            RankLabel.Text = Role
        end)

        -- Check group ranks and add icons
        if Player:GetRankInGroup(GroupId) >= AssetConfig.Group.Ranks.Developers.Rank then
            local DeveloperIcon = Icons.Developer:Clone()
            DeveloperIcon.Parent = CloneGui
        end

        if Player:GetRankInGroup(GroupId) >= AssetConfig.Group.Ranks.Management.Rank then
            local ManagementIcon = Icons.Management:Clone()
            ManagementIcon.Parent = CloneGui
        end
    end)
end)

awesome! Very helpful indeed. Needed this alot.