You can, but you need to be careful to avoid errors. For instance, in your example, if FindFirstChild returned nil, then attempting to call ":Clone()" will error because "nil:Clone()" is not valid.
This sort of error could occur without chaining, but you'd normally make sure that the values aren't nil before proceeding:
reference = game.ServerStorage:FindFirstChild(vehicleName)
if not reference then return end
vehicle = reference:Clone()
However, if you're positive that the model exists, there's nothing stopping you from doing this:
gameServerStorage[vehicleName]:Clone().Parent = workspace
Of course, if you need to call :MakeJoints on that model, you'll need to save the result of "Clone" to a variable so that you can access it more than once.
You can do this in general by creating functions that return the object they work on. ex:
function SetParent(obj, parent)
obj.Parent = parent
return obj
end
function MakeJoints(obj)
obj:MakeJoints()
return obj
end
function ColorModel(obj, color)
for _,p in ipairs(obj:GetChildren()) do
if p:IsA("BasePart") then
p.BrickColor = color
end
ColorModel(p, color)
end
return obj
end
SetParent(ColorModel(MakeJoints(game.ServerStorage["MyModel"]:Clone()), BrickColor.Random()), workspace)
SetParent(
ColorModel(
MakeJoints(
game.ServerStorage["MyModel"]:Clone()),
BrickColor.Random()),
workspace)
If you want to use the colon to join custom functions, you'll need to use inheritance, which gets much more complicated.
1 comment
As long as "vehicleName" is defined, then it is kind of possible. Since the method ":FindFirstChild()" returns the object if it finds it, or "nil" if it doesn't find it, then if the method returns "nil", nothing will be cloned.