I am trying to make a level bar but for some reason when ever the player reaches the required xp for the next level the bar stays the size (1,0,1,0) instead of (0,0,0,0). Here is the funtion:
function Change()
local currentLvl = plr:WaitForChild("leaderstats").Level.Value
local currentExp = plr:WaitForChild("leaderstats").Exp.Value
print(currentExp.." : Exp -- Level : "..currentLvl) --Prints 0 :Exp -- Level : 14
level.Text = "Level "..currentLvl
xp.Text = currentExp.."/"..currentLvl*25
bar:TweenSize(UDim2.new(currentExp/(currentLvl*25),0,1,0),"Out","Quad",.3)
if bar.Size == UDim2.new(nil,0,1,0)then
bar.Size = UDim2.new(currentExp/(currentLvl*25),0,1,0)
end
task.wait(.3)
if currentExp >= currentLvl*25 then
script.NextLevel:FireServer(currentExp,currentLvl) -- This will cause funtion to run again after level is changed
end
end
I am 100% sure that the function runs since it prints something in the output but the sizing of the bar is incorrect. Any help is appreciated
if currentExp >= currentLvl*25 then
currentExp = 0 -- This will make the EXP turn back to 0.
script.NextLevel:FireServer(currentExp,currentLvl) -- This will cause funtion to run again after level is changed
end
Also, you seem to be sending the server your current experience level. This is bad!
The client should tell the server if it’s performed an action that awards experience points, and the server should handle awarding the player.