Attempt to index a nil value issue

Hi, I’ve been trying to fix an issue with my Leveling system data, when it try’s to change the XP to *1.50. i get the error attempt to index a nil 'value'. Is there anything i done wrong?

if xp.Value >= maxXP.Value then --the line of code i get the error on.

Could you post the whole script?

Sure thing

removed issue fixed

Could you replace your xp.Changed Event with this and tell me if you get anything in the output just before the error?

xp.Changed:Connect(function()
    if xp then
        print(xp.Value)
    end
    if maxXP then
        print(maxXP.Value)
    end)
	if xp.Value >= maxXP.Value then
		leveling.Value = leveling.Value+1
		xp.Value = 0
		maxXP.Value = maxXP.Value*1.50
	end
end)

This is the output i get from that.
image

why dont you put your leveling stuff below the loading of data

Keeping codes clean for when the studio i work with hire’s other programmer’s and so it will be easy for them to understand what is what. If you know what i mean?

what is the val parameter used for?

I have found your issue, You are overwriting the maxXP IntValue with a number in the following code

pcall(function()
	levelingData = dataStores:GetAsync(player.UserId.."-Level")
	xpData = dataStores:GetAsync(player.UserId.."-XP")
	maxXP = dataStores:GetAsync(player.UserId.."-MaxXP")
end)

Replace maxXP with maxXPData and you should be set!

1 Like

Okay, thank you for the help! 30 characters