Hi, My problem currently is that I have leveling system connected to a Gui I made. The Gui updates to show what level you are and the current xp/max xp as well as moves the experience bar along as you get more experience. It’s calculating overflow experience and everything perfectly fine and it’s functional, BUT when the player levels up from say level 1 to level 2. If level 1’s exp bar was 49/50 where 50 experience is what is needed, and the level 2 exp bar is 0/100, as soon as they level up the Gui updates to show their new level and their current exp fine but it doesn’t show the new max exp until they get more experience again, which is a little annoying. So if they had 49/50 and got 5 xp, the bar would update to say 4/50 instead of 4/100, but once they get say 2 xp it will update to 6/100 and be fine after that. I have looked this up on the Devforum and Youtube and I haven’t quite figured out what is causing the problem. Please see if you can see the issue.
-- Player-related variables
local player = game.Players.LocalPlayer
local level = player:WaitForChild("Level")
local current = level:WaitForChild("Current")
local max = level:WaitForChild("Max")
-- Ui-related variables
local gui = script.Parent
local exterior = gui:WaitForChild("Exterior")
local label = exterior:WaitForChild("Label")
local exp = exterior:WaitForChild("Exp")
local bar = exterior:WaitForChild("Bar")
-- Change stats upon join
label.Text = "Level "..level.Value
exp.Text = current.Value.."/"..max.Value.." Xp"
bar.Size = UDim2.new(current.Value/max.Value, 0, 1, 0)
level.Changed:Connect(function(val)
label.Text = "Level "..level.Value
exp.Text = current.Value.."/"..max.Value.." Xp"
bar.Size = UDim2.new(current.Value/max.Value, 0, 1, 0)
for i = 1,5 do
local fireworks = Instance.new("Part")
fireworks.Shape = 0
fireworks.formFactor = "Symmetric"
fireworks.Size = Vector3.new(1,1,1)
fireworks.BrickColor = BrickColor.Random()
fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0)
fireworks.Parent = game.Workspace
game:GetService("Debris"):AddItem(fireworks, 2)
fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30))
end
end)
current.Changed:Connect(function(val)
exp.Text = current.Value.."/"..max.Value.." Xp"
bar.Size = UDim2.new(current.Value/max.Value, 0, 1, 0)
end)
The max variable is tied to the maxExperience value that is the problem. Thank you for taking the time to help me with my problem!