Why am i getting nil?

hi, i’m wondering why it says nil. i tried everything but i just says nil every
single time why does it keep doing that.

local script:

		
		item_Target = mouse.Target;
		item_String = item_Target.String;
		
		for _, i in pairs(items) do
			if i == item_String.Value then
				
				part0 = item_Target; -- this one is for some reason nil
				part1 = character.RightHand;
				
				item.pickup(part0, part1)
			end
		end
	end
end)

module script:

function item:pickup(part0, part1)
	print(part0, part1) -- printed out and part0 is nil
end

thanks

1 Like

Hello!
Make sure the “item” module script variable is requiring the module script.
e.g.

local moduleScript = require(script.ModuleScript)
moduleScript.run("Hello world!")

However, this won’t work

local moduleScript = script.ModuleScript
moduleScript.run("Hello world!")

This is because there is no instance called “run” inside the module script.

Also, make sure the function inside looks like this;

function item.pickup(part0, part1)
    print(part0, part1)
end

Sometimes having the dot replaced with a colon messes things up.
Hope this helps!

hi, i forgot to say that i’m using ego moose’s construct that’s why the function is this “:” then this “.”
also i found the problem i used this “:” for the function in my module script but in the local script is was this “.”

this is the wrong because i’m using this “:” in the module script

item.pickup(part0, part1)

this is the fixed version

item:pickup(part0, part1)

thanks for helping me find the solution :grinning:

No problem! I’m glad I could help!

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