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)
	SecondaryFrame:TweenSize(UDim2.fromScale(calculation, 1))

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"))

	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")
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()

1 Like