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:

01-- this function is called on a touched event
02local function createButtonsAndItems(serverBaseplate, tycoonBaseplate, savedItemsTable)
03 
04    for i,v in pairs(serverBaseplate:FindFirstChild("PurchasableItems"):GetChildren()) do
05 
06        if findAMatch(savedItemsTable, v) then
07 
08            local copy = serverBaseplate.PurchasableItems:FindFirstChild(v.Name):Clone()
09 
10            if copy:FindFirstChild("ItemType") then
11 
12                if copy.ItemType.Value == "Dropper" then
13 
14                    copy.Parent = tycoonBaseplate:FindFirstChild("PurchasedItems")
15 
16                    local oreMakerCopy = game.ServerStorage.ModuleScripts:FindFirstChild("OreMaker"):Clone()
17 
18                    oreMakerCopy.Parent = copy
19                    wait()
20                    require(oreMakerCopy)

inside the module script:

1wait(3)
2print(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:

1wait(3)
2local var = script.Parent.Name
3print(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