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
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