Attempt to index nil with 'Parent'

I am getting an error message saying MainScript:58: attempt to index nil with ‘Parent’. witch is the 2nd line from the bottom. There should be an upgrader that spawns in when a button is touched by a player. The button works but the upgrader doesn’t spawn in. All of the other buttons when touched are created but for some reason this object doesn’t spawn in.

--- Buying Functions---

for i, v in pairs(Buttons:GetChildren()) do
	local NewItem=BoughtItems:FindFirstChild(v.Item.Value)
	if NewItem~= nil then
		Items[NewItem.Name]=NewItem:Clone()
		NewItem:Destroy()
	else
		v.ButtonPart.Transparency=1
		v.ButtonPart.CanCollide=false
		v.ButtonPart.BillboardGui.Frame.Visible=false
		
	end

	if v:FindFirstChild("Dependency") then
		coroutine.resume(coroutine.create(function()
			v.ButtonPart.Transparency=1
			v.ButtonPart.CanCollide=false
			v.ButtonPart.BillboardGui.Frame.Visible=false
			if BoughtItems:WaitForChild(v.Dependency.Value, 100000) then
				v.ButtonPart.Transparency=0
				v.ButtonPart.CanCollide=true	
				v.ButtonPart.BillboardGui.Frame.Visible=true
			end
		end))
	end

	v.ButtonPart.Touched:Connect(function(Hit)
		if Hit and Hit.Parent:FindFirstChild("Humanoid") then 
			local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
			if Values.OwnerValue.Value==Player then
				if v.ButtonPart.CanCollide == true and v.ButtonPart.Transparency== 0 then
					if Player:WaitForChild("leaderstats").Cash.Value>=v.Price.Value then
						Player.leaderstats.Cash.Value-=v.Price.Value 
						Items[v.Item.Value].Parent= BoughtItems
						v:Destroy()
					end
				end
			end
		end
	end)
end

This is the script for the upgrader

local Debounce ={}

script.Parent.MainPart.Touched:Connect(function(Hit)
if Hit.Name== “Part” and Hit:FindFirstChild(“CashValue”) then
if not Debounce[Hit] then
Hit:FindFirstChild(“CashValue”).Value+= 5
Debounce[Hit]=true
end
end
end)

What is your error in the output?

Edit: i can read the topic, what line is it on?

MainScript:58: attempt to index nil with ‘Parent’
Items[v.Item.Value].Parent= BoughtItems

Can you show a screenshot the script on studio, it may be easier to find line 58 on there

You are trying to get a Value of an item, but you are trying to the Values Parent?

Just do this

Items[v.Item].Parent = BoughtItens
1 Like

Trying to get the value of the parent

From what i understand

Items[v.Item].Parent.Value = BoughtItems
2 Likes