Leveing guidance

Hello guys,
I am currently in need of help. I am working on a leveling system, but I ran into a problem. The XP progress bar doesn’t match up to the XP value.

XP progress bar
Screenshot 2024-03-30 131936

Player’s XP value
Screenshot 2024-03-30 132001

Leveling code and the location of my call.

local currencyManager = require(game.ServerScriptService.ModuleScripts:WaitForChild("CurrencyManager"))

local EachLevelXp = {
	4, -- Level 1
	6, -- Level 2
	7, -- Level 3
}

function EachLevelXp:Levelup(player : Instance)
	local SecondaryFrame = player.PlayerGui.Level.Primary.Secondary
	local PercentageTextlabel = player.PlayerGui.Level.Primary.Percentage
	local calculation = player.leaderstats.Xp.Value / EachLevelXp[player.leaderstats.Level.Value]
	local percentage = calculation * 100
	PercentageTextlabel.Text = percentage.."%"
	
	if player.leaderstats.Xp.Value >= EachLevelXp[player.leaderstats.Level.Value] and player.leaderstats.Level.Value < 3 then
		currencyManager:Remove(player, "Xp", EachLevelXp[player.leaderstats.Level.Value])
		currencyManager:Give(player, "Level", 1)
	end
	SecondaryFrame:TweenSize(UDim2.fromScale(calculation, 1))
end

return EachLevelXp

The location of my call

local ServerScriptService = game:GetService("ServerScriptService")
local PlayerService = game:GetService("Players")

local teamManager = require(ServerScriptService.ModuleScripts:WaitForChild("TeamManager"))
local LevelManager = require(ServerScriptService.ModuleScripts:WaitForChild("LevelManager"))

PlayerService.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local Xp = Instance.new("IntValue", leaderstats)
	Xp.Name = "Xp"
	
	local Level = Instance.new("IntValue", leaderstats)
	Level.Name = "Level"
	Level.Value = 1
	teamManager:JoinTeam(player, "Non_afk")
	
	player.CharacterAdded:Connect(function(character) 
		LevelManager:Levelup(player)
		
		Xp:GetPropertyChangedSignal("Value"):Connect(function()
			LevelManager:Levelup(player)
		end)
	end)
end)
1 Like

Bumping this thread due to no solution found

You need to take into account the size of the bar that is changing. Can you check if the bar’s max size is 1?

1 Like

I just noticed you were talking about the text label, my bad. Try to print out the percentage before applying it, print out the calculation to see if any of them return a nil value.

1 Like

Hello there,
I have fixed it already, but my text shows numbers like 0.098666. How do I fix this?

you can do math.round()
dsaiodsajiodsaoidjas

1 Like