Attempt to index nil with value

I am trying to make a gui which shows the player how much xp they have.
At line 20 in the script which displays it, I get an error reading: “Players.Eh_Canadian0.PlayerGui.Backpack.Score:20: attempt to index nil with ‘Value’”

NOTE: You can ignore the unbanked and banked parts, they (probably) aren’t part of the problem (or solution)

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList,false)

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")

-- Edit Score

local Unbanked = script.Parent.UnbankedScore
local Banked = script.Parent.BankedScore

local XP = leaderstats:FindFirstChild("XP")
local Rank = leaderstats:FindFirstChild("Rank")
local XPMax = (((Rank.Value*(Rank.Value - 1))/10) * 100) + 100

local XPGui = script.Parent:FindFirstChild("Experience")

while wait() do
	Unbanked.UnbankedGold.Text = leaderstats:FindFirstChild("UnbankedGold").Value
	Banked.BankedGold.Text = leaderstats:FindFirstChild("Gold").Value
	if XP.Value >= XPMax then -- Line 20: "attempt to index nil with value"

		XPGui.LVL.Text = "↑"
		wait (1.5)
		XPGui.LVL.Text = Rank.Value
		XPGui.Requirements.Text = XP.Value .. "/" .. XPMax
		XPGui.XPBar.Size = UDim2.new(XP/XPMax, 0, 1, 0)

	else

		XPGui.XPBar.Size = UDim2.new(XP.Value/XPMax, 0, 1, 0)
		XPGui.Requirements.Text = XP.Value .. "/" .. XPMax
		XPGui.LVL.Text = Rank.Value

	end
end
1 Like

does XP have a value property?

2 Likes

Could you show the part of the script that creates the leaderstats? Maybe it’s not creating the XP value and XP is nil

1 Like

You could change this:

For this:

local XP = leaderstats:WaitForChild("XP")
local Rank = leaderstats:WaitForChild("Rank")
1 Like

Wow it really was just that huh :confused:

Uh… You’re welcome, happy to help xd

1 Like