This script is suppose to change level when the xp hits a certain point, but it wont work. The Level/XP and everything else is all put in with Data Storage. Im not getting any errors either

Here is the script, I'm not sure what is wrong with it. It just wont level up..

local player = game.Players.LocalPlayer
local XP = player.XP.Value
local Level = player.Level.Value


function onXPChanged(player, XP, level) 
	if XP.Value>=level.Value * 20 then 
		XP.Value = XP.Value - level.Value * 20 
		level.Value = level.Value + 1
		player.Character.Humanoid.MaxHealth = player.Character.Humanoid.MaxHealth + 10
		player.Character.Humanoid.Health = player.Character.Humanoid.Health + 10
		player.Levelss.FAP.Value = player.Levelss.FAP.Value + 1
	end 
end 

function onLevelUp(player, XP, level) 
if player.Character~=nil then 
	for i = 1,5 do 
		local fireworks = Instance.new("Part") 
		fireworks.Shape = 0 
		fireworks.Material = "Neon"
		fireworks.formFactor = "Symmetric" 
		fireworks.Size = Vector3.new(1,1,1) 
		fireworks.BrickColor = BrickColor.Random() 
		fireworks.CFrame = player.Character.Head.CFrame + Vector3.new(0,2,0) 
		fireworks.Parent = game.Workspace 
		local fu = Instance.new("Fire")
		fu.Size = 5
		fu.Heat = 5
		fu.Color = Color3.new(math.random(),math.random(),math.random()) 
		fu.SecondaryColor = Color3.new(math.random(), math.random(), math.random())
		fu.Parent = fireworks 
		game:GetService("Debris"):AddItem(fireworks, 2) 
		fireworks.Velocity = Vector3.new(math.random(-30,30),math.random(-30,30),math.random(-30,30)) 
		end 
	end 
end 






function onPlayerEntered(newPlayer)
	XP.Changed:connect(function() onXPChanged(newPlayer, XP, Level) end) 
	Level.Changed:connect(function() onLevelUp(newPlayer, XP, Level) end) 

	newPlayer.CharacterAdded:connect(function(c) 
	c.Humanoid.MaxHealth = newPlayer.Levelss.Level.Value * 10 + 100
	c.Humanoid.Health = newPlayer.Levelss.Level.Value * 10 + 100 
	end) 
end 



game.Players.PlayerAdded:connect(onPlayerEntered)

The XP value changes like it is suppose to,but level will not increase

3 comments

0

Your question is more likely to be answered if your code is readable.

0

K. Indented it