Help with my leveling system

so whenever I get enough exp and I level up how would I increase the exp needed for the next level and set a level cap?

local player = game.Players.LocalPlayer
local xp = player:WaitForChild("Exp")
local level = player:WaitForChild("levels")
local maxExp = 10

xp.Changed:Connect(function()
	if xp.Value >= maxExp then
		script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)
		wait(0.5)
		xp.Value = 0
		script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)
		level.Value = level.Value + 1
	else
		script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)
	end
end)

script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)

Thats 1 script.

game.Players.PlayerAdded:Connect(function(player)
	local xp = Instance.new("IntValue", player)
	xp.Name = 'Exp'
	xp.Value = 1

	local level = Instance.new("IntValue", player)
	level.Name = 'levels'
	level.Value = 1
end)

1st script is a local script 2nd is a script.

Is the first script local or serversided?

Screen Shot 2022-02-11 at 12.41.22 AM

Serversided I think.

when you change the xp value, ur changing it from local script or server script??

I edited the first script, i added a max level cap and if you level up the required exp will increase

game.Players.PlayerAdded:Connect(function(player)
	local xp = Instance.new("IntValue", player)
	xp.Name = 'Exp'
	xp.Value = 1
	
	local level = Instance.new("IntValue", player)
	level.Name = 'levels'
	level.Value = 1
	
	local maxlevel = Instance.new("IntValue", player)
	maxlevel.Name = 'maxlevels'
	maxlevel.Value = 100
	
	local maxxp = Instance.new("IntValue", player)
	maxxp.Name = 'MaxExp'
	maxxp.Value = level * 100
	
	xp.Changed:Connect(function()
		if xp.Value >= maxxp.Value then
			if level.Value ~= maxlevel.Value then
				xp.Value -= maxxp.Value

				level.Value += 1
				maxxp.Value = level.Value * 100
			elseif level.Value == maxlevel.Value then
				xp.Value = 0
			end
		end
	end)
end)

I mean the serverside script got highly confused

Whenever I test it now there is nothing for me to change the value of the exp/level so now it won’t change my display for example a level/exp bar… Level: 1 | EXP: 1/100
Screen Shot 2022-02-11 at 1.11.22 AM

i tested this and it worked fine

game.Players.PlayerAdded:Connect(function(player)
	local folder = Instance.new("Folder", player)
	folder.Name = "levelsystem"
	
	local xp = Instance.new("IntValue", folder)
	xp.Name = 'Exp'
	xp.Value = 1

	local level = Instance.new("IntValue", folder)
	level.Name = 'levels'
	level.Value = 1

	local maxlevel = Instance.new("IntValue", folder)
	maxlevel.Name = 'maxlevels'
	maxlevel.Value = 100

	local maxxp = Instance.new("IntValue", folder)
	maxxp.Name = 'MaxExp'
	maxxp.Value = level.Value * 100

	xp.Changed:Connect(function()
		if xp.Value >= maxxp.Value then
			if level.Value ~= maxlevel.Value then
				xp.Value -= maxxp.Value

				level.Value += 1
				maxxp.Value = level.Value * 100
			elseif level.Value == maxlevel.Value then
				xp.Value = 0
			end
		end
	end)
end)

Make sure your leaderstat scripts are server scripts placed inside a suitable directory, i.e; the ServerScriptService folder.

it works but how would I make it display with the level and exp?

Try this

local player = game.Players.LocalPlayer
local xp = player.levelsystem:WaitForChild("Exp")
local level = player.levelsystem:WaitForChild("levels")

script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)

xp.Changed:Connect(function()
       script.Parent.Size = UDim2.new(xp.Value/maxExp,0,1,0)
end)

where and how should I put it I’m just really confused on this whole thing right now, like do I put it in a text label like where would I place it lmao sorry for taking so long to figure sum out lol.