Attempt to call a nil value error

I am trying to make a tycoon game, but when I try to use an in pairs loop to change the transparency of a bunch of parts it says that the part in the table is a nil value.

local tycoon = script.Parent.Parent.Parent.Parent

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		if player.UserId == tycoon.OwnerId.Value then
			if script.Parent.Transparency == 0 then
				if player.leaderstats.Cash.Value >= 1000 then
					script.Parent.Transparency = 1
					script.Parent.Parent.Part2.Transparency = 1
					script.Parent.BillboardGui.Enabled = false
					player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - 1000
					local lightParts = {tycoon.Lights:GetDescendants()}
					for i, v in pairs(lightParts) do
						if v:IsA("Part") then -- this is were it gets the error
							if v.Name == "Part" then
								v.Transparency = 0
							end
						end
					end
				end
			end
		end
	end
end)

Screenshot (2)
This is what is in the Lights folder.

Attempt to call a nil value error
The error that I get.

You don’t need to put tycoon.Lights:GetDescendants() in a table it’s already a table when you call in GetDescendants().

1 Like

Why not just use :GetChildren() instead?

    local lightParts = tycoon.Lights:GetChildren()
    for _, v in pairs(lightParts) do
       local lightPart = v.Part
       lightPart.Transparency = 0
   end

thanks, i have been trying to fix this for 2 days.