Clone vs fromExisting

Is there any difference between the two functions? The only difference I’ve noticed is the error messages. Is there any behaviour or performance difference?

It’s already explained by roblox staff.

It will be documented on the creator hub, but it was only turned on late last week so the updated doc isn’t up yet.

TL;DR: It only copies the properties, not the children. You probably don’t need it, it’s intended to be used in the implementation of low level libraries / systems which want to partially copy stuff like custom streaming code.

1 Like

A little question just to understand a bit more of Instance.fromExisting:

If I were to use it into a children, it would simply copy its properties, right? For instance: It would copy the same statement where the instance is anchored

You could implement clone (except for redirecting reference props like PrimaryPart) using it like this:

local function clone(original: Instance)
    if not original.Archivable then
        return
    end
    local copy = Instance.fromExisting(original)
    for _, ch in original:GetChildren() do
        local chCopy = clone(ch)
        if chCopy then
            chCopy.Parent = copy
        end
    end
    return copy
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.