Need help resetting XP bar

so I have made this XP bar that works fine when it goes up but when I level up I want it to reset but I cannot for the life of me find out how, here is my script which is in a local script, any help is appreciated.

local player = game.Players.LocalPlayer

local EXP = player.leaderstats.EXP
local ReqEXP = player.leaderstats.ReqEXP
local level = player.leaderstats.Level

EXP.Changed:Connect(function(Changed)
	if Changed then
		
		script.Parent.expBar:TweenSize(UDim2.new(EXP.Value/ReqEXP.Value, 0, 1, 0))
		
	end
end)

1 Like

Where is the level.Changed function?

i tried to use it but it didnt work so i removed it

You have to have both in place, and must do it in a server script

but wouldn’t making the UI bigger in a server script ruin it for the rest of the server players?

Try using remote Events with the local script just acting as the changes that specific player can see

1 Like

I was able to find a way to do it here is my script, it is located in a local script

local player = game.Players.LocalPlayer

local EXP = player.leaderstats.EXP

local ReqEXP = player.leaderstats.ReqEXP

local level = player.leaderstats.Level

EXP.Changed:Connect(function()

script.Parent.expBar:TweenSize(UDim2.new(EXP.Value/ReqEXP.Value,0,1,0),"Out","Sine",0.5,true)

end)

script.Parent.expBar:TweenSize(UDim2.new(EXP.Value/ReqEXP.Value,0,1,0),"Out","Sine",0.5,true)

EXP.Changed:Connect(function()

if EXP.Value >= ReqEXP.Value then

script.Parent.expBar:TweenSize(UDim2.new(0, 0,1, 0))

end

end)
  1. set EXP.Value to equal 0
  2. at the end of your tween include the override boolean and set it to true to see the most updated status:
script.Parent.expBar:TweenSize(
UDim2.new(EXP.Value/ReqEXP.Value, 0, 1, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, true)
1 Like