Hello, I am using a module script to clone objects found in ReplicatedFolder and in a given parent if I wanted, where the objects all have unique names.
Currently I can check if I am specifying a parent or if I have any arguments at all. The issue is that I do not know how to return an error if the parent does not exist.
For example, if I do…
print(objectHandler:Get('Tool', foo):GetFullName())
and it would only print out Tool
with no error whereas doing…
print(objectHandler:Get('Tool', workspacee):GetFullName())
prints out Workspace.Tool
.
I’ve considered using FindFirstChild
but each time I call this, the parent of the Child could vary, like Workspace
and Player.Backpack
.
Any help is appreciated.
Here is my code so far:
local objectHandler = {}
local scope = game:GetService('ReplicatedStorage')
function objectHandler:Get(objectName_, newParent_)
if objectName_ then
local object = scope:FindFirstChild(objectName_, true)
if object then
local newObject = object:Clone()
if newParent_ then --check validity of parent somewhere inside here
newObject.Parent = newParent_
return newObject
else
return newObject
end
else
return error('CANNOT FIND [ ' .. objectName_ .. ' ] IN [ ' .. tostring(scope) .. ' ]')
end
else
return error('NO ARGUMENTS FOUND')
end
end
return objectHandler