For some reason this error comes up any help? attempt to index upvalue 'Xpn' (a number value)
local plr = game.Players.LocalPlayer local Xp = plr:WaitForChild("XP") -- Using WaitForChild() so the script won't break if "XP" has not loaded yet. local lvl = plr:WaitForChild("lvl") local Xpn = plr:WaitForChild("XpNeeded") -- How much more xp does a person need lvl.Changed:Connect(function() if lvl.Value == 2 then -- How much Xp needed will get updated Xpn = Xpn.Value+50 end end) lvl.Changed:Connect(function() if lvl.Value == 3 then -- How much Xp needed will get updated Xpn = Xpn.Value+75 end end) lvl.Changed:Connect(function() if lvl.Value == 4 then -- How much Xp needed will get updated Xpn = Xpn.Value+100 end end) lvl.Changed:Connect(function() if lvl.Value == 5 then -- How much Xp needed will get updated Xpn = Xpn.Value+125 end end) Xp.Changed:Connect(function() if Xp.Value >= Xpn.Value then Xp.Value = Xp.Value-Xpn.Value lvl.Value = lvl.Value+1 end end)`
Essentially, you're setting Xpn (A number value) equal to the value of itself, when you should be setting the Value of Xpn to itself.
Additionally, you are using more than one .Changed
for the same value, which is unneeded.
Revised code:
local plr = game.Players.LocalPlayer local Xp = plr:WaitForChild("XP") -- Using WaitForChild() so the script won't break if "XP" has not loaded yet. local lvl = plr:WaitForChild("lvl") local Xpn = plr:WaitForChild("XpNeeded") -- How much more xp does a person need lvl.Changed:Connect(function() if lvl.Value == 2 then Xpn.Value = Xpn.Value + 50 end if lvl.Value == 3 then Xpn.Value = Xpn.Value + 75 end if lvl.Value == 4 then Xpn.Value = Xpn.Value + 100 end if lvl.Value == 5 then Xpn.Value = Xpn.Value + 125 end end) Xp.Changed:Connect(function() if Xp.Value >= Xpn.Value then Xp.Value = Xp.Value - Xpn.Value lvl.Value = lvl.Value + 1 end end)
If I helped you, then be sure to upvote and accept my answer!
Happy scripting!