NotZylon
(shiesty)
March 25, 2021, 8:57pm
#1
Im not sure why this is happening, can someone help me please
local bar = script.Parent.BackFrame.Expbar
local text = script.Parent.TextLabel
local player = game.Players.LocalPlayer
local level = player.leaderstats.Level
local expStat = player.leaderstats.Exp
local expNeeded = tonumber(100 * math.exp(level.Value))
text.Text = expStat.Value.."/"..expNeeded
local change = expStat.Value / expNeeded
bar:TweenSize(UDim2.new(change,0,1,0),"In","Linear",0.5)
expStat.Changed:Connect(function()
expNeeded = tonumber(100 + math.exp(level.Value * 2))^level.Value
text.Text = expStat.Value.."/"..expNeeded
local change = expStat.Value / expNeeded
bar:TweenSize(UDim2.new(change,0,1,0), "In","Linear",0.5)
end)
level.Changed:Connect(function()
expNeeded = tonumber(100 + math.exp(level.Value * 2))^level.Value
text.Text = expStat.Value.."/"..expNeeded
local change = expStat.Value / expNeeded
bar:TweenSize(UDim2.new(change,0,1,0), "In","Linear",0.5)
end)
Where local change is, try putting this here instead.
local change = 0
if expStat.Value > expNeeded then
change = 1
else
change = expStat.Value / expNeeded
end
If expStat is greater than expNeeded then the change value will be greater than 1 and it’ll go over the bar.
NotZylon
(shiesty)
March 25, 2021, 9:06pm
#3
Its working but when it reaches the full bar, the bar doesn’t reset back
Where does expStat and the level variable get changed? It should only remain full if expStat is greater than expNeeded.
NotZylon
(shiesty)
March 25, 2021, 9:13pm
#5
oh, how can i make it so it resets?
You would have to use an on changed event (on the server) to check if the exp is greater than the expneeded. If it is, set the exp value to 0 and set the level to itself plus one.
Your issue lies in that you are setting the raw value of the expStat.Value / expNeeded to the bar’s scale value. Try doing,
change = expStat.Value / expNeeded
change = change * barScale
Where barScale is how big you want the bar’s scale to be at 100% xp.
NotZylon
(shiesty)
March 25, 2021, 10:38pm
#9
but how do i tween the exp to go lower
Where barScale is how big you want the bar’s scale to be at 100% xp. How big you want it to be, that is the value of barScale.
NotZylon
(shiesty)
March 25, 2021, 11:13pm
#12
but im not sure what to set that value to
If you want the bar to only be a quarter of the width of the screen, set it to 0.25. If you want it to be half the screen, use 0.50.
…barScale is the size of the xp that you want it to be when your xp is completely full.
NotZylon
(shiesty)
March 26, 2021, 2:02am
#17
oh alright. Why wont the exp update after it reached maxed
Could we see the updated script?
NotZylon
(shiesty)
March 26, 2021, 2:23am
#19
local bar = script.Parent.Bruh.Expbar
local text = script.Parent.TextLabel
local player = game.Players.LocalPlayer
local level = player.leaderstats.Level
local expStat = player.leaderstats.Exp
local expNeeded = tonumber(100 * math.exp(level.Value))
local barScale = 0.50
text.Text = expStat.Value.."/"..expNeeded
local change = 0
if expStat.Value > expNeeded then
change = 1
else
change = expStat.Value / expNeeded
change = change * barScale
end
bar:TweenSize(UDim2.new(change,0,1,0),"In","Linear",0.5)
expStat.Changed:Connect(function()
expNeeded = tonumber(100 + math.exp(level.Value * 2))^level.Value
text.Text = expStat.Value.."/"..expNeeded
local change = expStat.Value / expNeeded
bar:TweenSize(UDim2.new(change,0,1,0), "In","Linear",0.5)
end)
level.Changed:Connect(function()
expNeeded = tonumber(100 + math.exp(level.Value * 2))^level.Value
text.Text = expStat.Value.."/"..expNeeded
local change = expStat.Value / expNeeded
bar:TweenSize(UDim2.new(change,0,1,0), "In","Linear",0.5)
end)
Could be a number of reasons why the exp bar doesn’t reset. Could be that you’re not properly updating the player’s level, could also be that you are running multiple tween’s on the exp bar, but none of them override each other.