I’ve searched long and hard, but simply cant find an answer, my guess is roblox probably doesnt have a solution built in, In that case.
Any other ways to tell if something gets cloned?
I’ve searched long and hard, but simply cant find an answer, my guess is roblox probably doesnt have a solution built in, In that case.
Any other ways to tell if something gets cloned?
You could just add a boolean attribute to an object, and if that object was cloned, set the attribute to true.
Oh yeah probably shoulda mentioned this,
my intention is to do it automatically, as I am making something that’ll probably end up being open sourced, making all the users set an attribute after cloning said thing probably isnt the best way to go about it
Can’t you make your own clone function then? Something like
function Clone(instance)
local clonedInstance = instance:Clone()
-- set attribute of cloned instance here, do other stuff, etc
end
you could detect if the new instance was added into wherever its supposed to be added and then insert it into a table
This clone function would need to be accessible everywhere, and where using a module would work, I would rather just not you know.
Hmm yes this might work.
Thought about it for a bit, when you clone an object it gets parented to nil correct? Well in that case I can just detect when that happens, all though not the best method, it should work for what I am doing
yes, whenever an object is cloned the parent is automatically nil, make sure that if you’re doing any changes to the object (whether it be visual or something else) you do that before it is parented to wherever you want to put it so the game does not have to render it twice
No, you would have to wrap the cloning behavior so you can add a tag or something to the instance to indicate that it is a clone. This would provide the automatic behavior you’re looking for, but you would have to run your clones through the module you made.
There is probably an easier way to do this. Unfortunately, I am extremely sleep deprived, so this is the best I can do for now. First use an event to wait until an object is created. Just like this terrifying snipped below:
game.DescendantAdded:Connect(function(desc)
The next step is to use a for loop and iterate through the object’s siblings like so:
for _, v in pairs(desc.Parent:GetChildren() do
if v ~= desc then
-- do more stuff
end
end
In that little “do more stuff” part, we iterate through every sibling iterate through every single property of the object by using this handy dandy module that OP wrote specifically for me to throw back at them. Depending on your use case, you may want to remove the Name and/or Parent exceptions because those might matter, and you’ll also have to add any classes that would apply. End product should look something like this.
local Module = require(Properties+Module)
game.DescendantAdded:Connect(function(desc)
for _, v in pairs(desc.Parent:GetChildren()) do
if v ~= desc then
if Module.HasSameProperties(desc, v) then
print("is a clone of this object!!! :D")
return
else
print("is not a clone of this object :C")
end
end
end
end)
You’ll have to add your parameters so that it only runs when you want to, and make any other necessary tweaks as I don’t know for certain how this is supposed to work in your game.
Should work!! Although it is extremely hacky!!! Please let me know if something doesn’t work so that I can cry.
maybe u could just a tag called “Cloned” to it? and then if u want to check, then just do HasTag?
After second thought, telling if said thing gets parented to nil isnt something easy to do considering I would need to connect a GetPropertyChangedSignal to it, of which I would need this to be automatic and isnt exactly the best way to go, so instead Im just going to store all of the things in a table like you mentioned, it’ll probably be the most convenient.
which wouldnt exactly make it automatic though, as Id have to do that manually.
Although this could work, only problem I face is the fact that multiple objects could have the same properties but not in fact be clones of each other
How could they not be clones of each other if they have the same properties
Well take for instance UICorners, most of them in ones game would share the exact properties, but wouldnt be clones of each other
No, there isn’t really a way to do that. Unless, you see if a instance is added in the entire game and check every instance in your game to see what object that instance matches with and then you can consider it a clone.
UI Elements such as a UICorner can be distinguishe by their Parent or Adornee. If two UICorners have the same properties, including the same parent, you can be certain it’s a clone, as there would be no logical reason to have 2 UICorner objects adorned to the same object with the same modifications.
I can see what you mean. And while there isn’t a way to perfectly identify cloned objects, this is probably the closest you can get within the constraints of luau.
well see the thing is, when you clone something it gets parented to nil, in most cases the clone doesnt get parented back to its original parent, thus I am unable to tell if it is a clone
well, you can use the built in property called IsAClone
property to check
realistically, i don’t think you can without using attributes,
just because it’s going to be open source doesn’t mean it has to be entirely stupid proof
Reuse this code as a utility function whenever you need to clone an instance
local function Clone(instance)
print(instance.Name .. " is cloned")
return instance:Clone()
end