ItemView is not a valid member of ImageLabel

So I am working on a system, where can equip and unequip weapons, for some reason as you can see if the first for loop, it gets an error saying ItemView is not a valid member of ImageLabel. and in the second for loop it works?

Check.Checkit = function(player, open1, open2, frame, about)
	if open1 == true and open2 == true then 
		if about == "Sword" then
			for i, v in pairs(frame.ItemView:GetChildren()) do
				EquipEvent:FireServer("UnEquip", v.Name, v.AttackScript.Animation.Id.Value)
			end
		elseif about == "Inv" then
			if #player.PlayerGui.Inventory.Character.Sword:GetChildren() == 1 then
				print("Something is currently equipped!")
			else
				frame.Parent = player.PlayerGui.Inventory.Character.Sword
				frame.Size = UDim2.new(1,0,1,0)
				frame.Position = UDim2.new(0.5,0,0.5,0)
				for i, v in pairs(frame.ItemView:GetChildren()) do
					local serial = v.Stats.Serial.Value
					EquipEvent:FireServer("Equip", v.Name, v.AttackScript.Animation.Id.Value, serial)
				end
			end
		end
	end
end

This is the script that sends the frame:

local frame = script.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Parent.Name == "Sword" then
		local clone = script.Parent.Parent:Clone()
		script.Parent.Parent:Destroy()
		clone.Parent = player.PlayerGui.Inventory.Inventory.Inventory
		Check.Checkit(player, Inv_Open.Value, Char_Open.Value, frame, "Sword")
	elseif script.Parent.Parent.Parent.Name == "Inventory" then
		Check.Checkit(player, Inv_Open.Value, Char_Open.Value, frame, "Inv")
	end
	
end)
1 Like

What line is the error on? It’ll help others track down the error.

Line 4 in the first script. That’s the first for loop which doesn’t work.

Try to use :FindFirstChild("ItemView") instead of just dot.

Can you show a picture of the explorer? It’s hard to say what’s wrong without context. The error is saying there’s nothing inside a specific ImageLabel (frame) called ItemView, though.

@ArticGamerTV That’ll just cause it to return nil and error because you can’t GetChildren of a nil value.

2 Likes

This doesn’t work, this is the error:
attempt to index nil with ‘GetChildren’

1 Like

Are you sure that there is more objects parented to this object since I think that this error comes when there is no any objects inside specific object.

This is the template of the of the frame, usally inside of itemView is a tool, I have checked on server and it shows a tool there.

image

As you can see the red, this is where it is equipped and when the unequip it should go back to inventory, which it does but I get an error.

image

Video:

1 Like

Try and make ItemView a variable and do :WaitForChild(). So like this:

ItemView = frame:WaitForChild("ItemView")

and then

for i,v in pairs(ItemView:GetChildren()) do
 -- Do whatever
end

The error seems to go, but the script breaks as in the whole unequip process just stops working.

I wouldn’t really see a reason on why :WaitForChild() would break a whole system as it says what it does, and that is it waits for the child of the item. Maybe your unequip system was already broken? Did it work before you put in :WaitForChild()?

So the when I would unequip it would set all value of equipped weapon to 0 in the datastore, and then print it out, but now for some reason it doesn’t. I will look more into it and see if I can fix it.

Hmmmm try checking the children in loop if it exists

if v ~= nil then

Fourth argument is missing there?

EquipEvent:FireServer("UnEquip", v.Name, v.AttackScript.Animation.Id.Value)

Thanks everyone for the help, I figured out the problem. The problem was that the frame being sent was destroyed and so when it sent it got a nil value, So I simply got rid of the line which destoryed it and cloned it, deleted those lines completely, and did it all in the module script instead and this seems to works so far. I appreciate all the help. I will mark this reply as a solution.

script.Parent.MouseButton1Click:Connect(function()
	if script.Parent.Parent.Parent.Name == "Sword" then
		Check.Checkit(player, Inv_Open.Value, Char_Open.Value, frame, "Sword")
	elseif script.Parent.Parent.Parent.Name == "Inventory" then
		Check.Checkit(player, Inv_Open.Value, Char_Open.Value, frame, "Inv")
	end
end)

Module Script:

Check.Checkit = function(player, open1, open2, frame, about)
	if open1 == true and open2 == true then 
		if about == "Sword" then
			for i, v in pairs(frame.ItemView:GetChildren()) do
				frame.Parent = player.PlayerGui.Inventory.Inventory.Inventory
				EquipEvent:FireServer("UnEquip", v.Name, v.AttackScript.Animation.Id.Value, 0)
			end
		elseif about == "Inv" then
			print(frame.Parent)
			if #player.PlayerGui.Inventory.Character.Sword:GetChildren() == 1 then
				print("Something is currently equipped!")
			else
				frame.Parent = player.PlayerGui.Inventory.Character.Sword
				frame.Size = UDim2.new(1,0,1,0)
				frame.Position = UDim2.new(0.5,0,0.5,0)
				for i, v in pairs(frame.ItemView:GetChildren()) do
					local serial = v.Stats.Serial.Value
					EquipEvent:FireServer("Equip", v.Name, v.AttackScript.Animation.Id.Value, serial)
				end
			end
		end
	end
end