Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[Solved]Why is this module scripts parent nil when I set the parent in a function?

Ok I will let the script talk for itself:

-- this function is called on a touched event
local function createButtonsAndItems(serverBaseplate, tycoonBaseplate, savedItemsTable)

	for i,v in pairs(serverBaseplate:FindFirstChild("PurchasableItems"):GetChildren()) do

		if findAMatch(savedItemsTable, v) then

			local copy = serverBaseplate.PurchasableItems:FindFirstChild(v.Name):Clone() 
			
			if copy:FindFirstChild("ItemType") then

				if copy.ItemType.Value == "Dropper" then
					  
					copy.Parent = tycoonBaseplate:FindFirstChild("PurchasedItems")
					
					local oreMakerCopy = game.ServerStorage.ModuleScripts:FindFirstChild("OreMaker"):Clone()

					oreMakerCopy.Parent = copy
					wait()
					require(oreMakerCopy)

inside the module script:

wait(3)
print(script.Parent.Name)

Output: OreMaker:2: attempt to index field 'Parent' (a nil value) the error is on line two of the module script

3 comments

0

Run the game and see if the Module Script actually copied and parented to the copy place

0

Oh yeah thx

0

will try

1 answer

you cant print parents or scripts. Try making a seperate variable instead. Example:

wait(3)
local var = script.Parent.Name
print(var)

This should work!

2 comments

0

actually you can

0

I only used print because on line three I have a variable that says dropper = script.Parent and the output is the same: parent a nil value

This discussion is preserved as it was. New answers, comments, and votes are closed.