Attempt to index nil with "Name"

I’m making a spamton shop,where you can get quests,from which you’ll get delicious [KROMER].
The issue is in the line 45,here is it:
if plr.SoulFragments:FindFirstChild(current.Value.Materials.Main.Value.Name) then.
I also tried removing the “Name” thing,and it said,that,Argument 1 missing or nil.
Anyways,here is the script:

local current = script.Parent.Current
local plr = game.Players.LocalPlayer
local Quest = game.Lighting.SpamtonQuest:GetChildren()
script.Parent.TextOutline.Text.Text = current.Value.Text.Value
local db = false
for i,v in pairs(Quest) do
	local thing = script.Parent.Template:Clone()
	thing.Text = v.Text.Value
	thing.Visible = true
	thing.Parent = script.Parent.DealList
	thing.MouseButton1Click:Connect(function()
		if db == false then
			db = true
			script.Parent.Changer:FireServer(v)
			wait(0.1)
			local text = v.Text.Value
			for i = 1,#text,1 do
				script.Parent.TextOutline.Text.Text =  string.sub(text,1,i)
				wait(0.05)
			end
			wait(0.1)
			db = false
		end
	end)
end
script.Parent.Leave.MouseButton1Click:Connect(function()
	if db == false then
		db = true
		local text = "YOU'RE LEAVING!? WHAT ABOUT MY DISK!?!?"
		for i = 1,#text,1 do
			script.Parent.TextOutline.Text.Text =  string.sub(text,1,i)
			wait(0.05)
		end
		script.Parent.Changer:FireServer(Quest[math.random(1, #Quest)])
		wait(1)
		script.Parent.Enabled = false
		script.Parent.TextOutline.Text.Text = current.Value.Text.Value
		wait(1)
		db = false
	end
end)
script.Parent.Buy.MouseButton1Click:Connect(function()
	if current.Value ~= nil and db == false then
		db = true
		if plr.SoulFragments:FindFirstChild(current.Value.Materials.Main.Value.Name) then
			if plr.SoulFragments:FindFirstChild(current.Value.Materials.Main.Value.Name).Value >= current.Value.Materials.Main.Cost.Value then
				local text = "DELICIOUS [KROMER]"
				for i = 1,#text,1 do
					script.Parent.TextOutline.Text.Text =  string.sub(text,1,i)
					wait(0.05)
				end
				game.Lighting.BuyKromer:FireServer(current.Value)
			else
				local text = "WHAT!? YOU WERE SO CLOSE!!"
				for i = 1,#text,1 do
					script.Parent.TextOutline.Text.Text =  string.sub(text,1,i)
					wait(0.05)
				end
			end
		end
		db = false
	end
end)

You are trying to get the name of the Value of Main, which doesn’t exist. Remove the value and instead do Main.Name, as Main has that property

This simply means that the Instance did not exist then, and there are many reasons to why this happens.

Would you mind sending us the hierachy of the script during error? It might help us understand more to what’s going on.
Additionally, check if current.Value.Materials.Main.Value had existed yet before running the code. Note that if the parent did not exist, this would error as well.

-- insert code above
	if current.Value ~= nil and db == false then
		db = true
		if current.Value.Materials.Main.Value then -- check if it exists
			if plr.SoulFragments:FindFirstChild(current.Value.Materials.Main.Value.Name) then
				-- insert code in between
			end
		end
		-- insert code below

just making it more clear

.Value is nil*

different error, the error op told was “attempt to index nil with Name”, the only line when the op indexed Name is on .Value

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.