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

findFirstChild and cloning issue, not sure what this problem is?

Asked by
Kryptio 19
6 years ago
Edited 6 years ago

I am not sure why but this is not cloning the FindArea, I have those print function in there only for debugging purposes and it says House2 and it gives me the correct FindArea.Parent, but it won't clone and I'm not sure why I can rename it, I can move it, but I cant make a duplicate. Anyone know why?

game.Workspace.Teleports.MasterAreaValue.Value = v.AreaValue.Value --Locates the Teleports AreaValue, in this case House2
local MasterAreaValue = TeleportsFolder.MasterAreaValue.Value --Locates the MasterAreaValue.Value which is House2 
local AreasFolder = game.ReplicatedStorage.Areas --Locates the Areas Folder
local FindArea = AreasFolder:findFirstChild(MasterAreaValue) -- Finds the first child named after the MasterAreaValue which is House2

print(MasterAreaValue) --Prints House2
FindArea:Clone() --Where its suppose to Clone but does nothing
print(FindArea.Parent) --Prints the parent of FindArea which is Area

--FindArea.Name = "CloneArea"
--game.ReplicatedStorage.Areas.CloneArea.Parent = game.Workspace

1 answer

Log in to vote
1
Answered by
UgOsMiLy 1074 Moderation Voter
6 years ago

When you clone an instance, the clone's parent is nil, so you would have to set its parent yourself. You do this by making the clone a variable and setting its parent. To do this, you would put:

local CloneArea = FindArea:Clone()

CloneArea.Parent = workspace

Another way is:

FindArea:Clone().Parent = workspace but if you want to mention the clone anywhere else in your script, you would use the first method.

Secondly, findFirstChild is deprecated. The new method is FindFirstChild (first letter is uppercase.)

Finally, it's best to use workspace, as it is easier.

workspace.Teleports.MasterAreaValue.Value = v.AreaValue.Value
local MasterAreaValue = TeleportsFolder.MasterAreaValue.Value
local AreasFolder = game.ReplicatedStorage.Areas
local FindArea = AreasFolder:FindFirstChild(MasterAreaValue)

print(MasterAreaValue)
local CloneArea = FindArea:Clone()
CloneArea.Parent = workspace
print(FindArea.Parent)

--FindArea.Name = "CloneArea"
--game.ReplicatedStorage.Areas.CloneArea.Parent = game.Workspace
0
Awesome i think the issue was just the deprecated method i was using. I was working with this for over an hours time over something really simple thanks! Kryptio 19 — 6y
0
Just because you don’t have to type “game.Workspace”, doesn’t mean it’s better than “workspace”, :thinking: 1TheNoobestNoob 717 — 6y
Ad

Answer this question