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
Player’s XP value
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)