Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
Edited 6 years ago

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

0
Run the game and see if the `Module Script` actually copied and parented to the `copy` place Zafirua 1348 — 6y
0
Oh yeah thx User#21908 42 — 6y
0
will try User#21908 42 — 6y

1 answer

Log in to vote
0
Answered by
s1muIate -35
6 years ago

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!

0
actually you can User#19524 175 — 6y
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 User#21908 42 — 6y
Ad

Answer this question