How do i make FindFirstChild() find a variable

So I’m making a function that’s in a module script. Here is the code:

function module.example(y)
	local variable = script.InventorySettings.FrameWidth.Inventory:FindFirstChild(y)
    print(variable.Name)
end

Basically, Im supposed to write module.example("Frame"), And each one of these have a different number at the end and it would print the part’s name but instead it prints this: Argument 1 missing or nil
and the error is coming from this part of the script:

local variable = script.InventorySettings.FrameWidth.Inventory:FindFirstChild(y)
1 Like

If the FindFirstChild function can’t find anything, it will return an error if you try to use variable.Name. Try changing your code to this:

function module.example(y)
	local variable = script.InventorySettings.FrameWidth.Inventory:FindFirstChild(y)
	if variable then
		print(variable.Name) 
	end
end

Sounds like y is nil. Where are you calling the function from? Follow the stack trace.