Level up script not working

I am trying to make a level up script, but it doesn’t seem to work. I am trying to change the size of a GUI based on the XP value.
My script inside Serverscript

local click = workspace.Part.ClickDetector

 game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
	
	local Level = Instance.new("IntValue", leaderstats)
	Level.Value = 0
	Level.Name = "Level"
		
	local XP = Instance.new("IntValue", leaderstats); XP.Name = "XP"
	XP.Value = 0 
	
	local MaxValue = Instance.new("IntValue", Level)
	MaxValue.Value = 100
	MaxValue.Name = "Max"
		
		
		
	XP.Changed:Connect(function()
		if XP.Value >= MaxValue.Value then
			Level.Value = Level.Value + 1
			XP.Value = 0
		end
	end)
click.MouseClick:Connect(function()
	XP.Value = XP.Value + 25
	
end)
end)

Script inside ScreenGUI.

local XPFRAME = script.Parent.Frame.Frame.XP
local LevelFrame = game.StarterGui:WaitForChild("ScreenGui").TextLabel

local player = game.Players.LocalPlayer
local Level = player.leaderstats.Level
local XP = player.leaderstats.XP
local maxXP = Level.Max

XPFRAME.Size = UDim2.new(XP.Value/maxXP.Value, 0, 1, 0)


Level.Changed:Connect(function()
XPFRAME.Size = UDim2.new(XP.Value/maxXP.Value, 0, 1, 0)


end)
			

this only updates when the level is changed, not the xp. Consider adding this at the end of your client script:

XP.Changed:Connect(function(new)
    XPFRAME.Size = UDim2.new(new/maxXP.Value, 0, 1, 0)
end)
2 Likes