I’m trying to create an XP level bar for my game, I have the XP/Level functions complete and now I just need to display it on the client. The issue I’m having now is when the player gets to the next level it goes to about the halfway point instead of starting at the bar.
Example:
I’ve been working on this for a bit now and can’t seem to figure it out. This is the client code I have for it:
local myTotalXP = myStats.Experience
local myCurrentLevel = myStats.Level
local currentLevelBaseXP = LevelService:GetExperience(myCurrentLevel)
local nextLevel,nextLevelXP = myCurrentLevel+1,LevelService:GetExperience(myCurrentLevel+1)
local xpThisLevel = math.clamp((myTotalXP-currentLevelBaseXP),0,nextLevelXP)
StatsFrame.LevelBar.Bar:TweenSize(UDim2.new(myTotalXP/nextLevelXP,0,1,0),"Out","Sine",0.1,true)
Instead of myTotalXP/nextLevelXP this.
Shouldn’t it just be currentExpIntoLevel/nextLevelXP this.
currentExpIntoLevel doesn’t exist but it would represent the amount of exp earned during the current level as opposed to “myTotalExp” which I presume is a tally of exp earned throughout all levels.
Looking again I notice you declare a variable named “xpThisLevel” which seems to fit this description, instead that should be used for the tween.
Thanks for this, while it didn’t resolve my issue completely- it helped me get to my final solution. Just that on its own produced a different strange result that you could reproduce on your own if you’re interested. Otherwise, this is what I did to completely fix the issue to produce the desired result:
local myTotalXP = myStats.Experience
local myCurrentLevel = myStats.Level
local currentLevelBaseXP = LevelService:GetExperience(myCurrentLevel)
local nextLevel,nextLevelXP = myCurrentLevel+1,LevelService:GetExperience(myCurrentLevel+1)
local xpThisLevel = math.clamp((myTotalXP-currentLevelBaseXP),0,nextLevelXP)
StatsFrame.LevelBar.Bar:TweenSize(UDim2.new(xpThisLevel/(nextLevelXP-currentLevelBaseXP),0,1,0),"Out","Sine",0.1,true)