Question about comparing instances

Hi. So, what I’m wondering is. If I was to have a table and append an instance such as a sound object like so:

foo = {soundObject}

If I was to then clone the instance and also append it to the table like so:

foo = {soundObject, soundObject}

Then, keep a reference of the second instance in a variable:

a = foo[2]

If I looped through the table, comparing the instance at each index with the above mentioned reference, would it only return true at the second index?

Yes it would return true only at the second index if you cloned it, right now in your example its not cloned, “a” is holding a reference to same sound object that the table is at the second index. This would happen because when you clone the sound object, the sound object clone would point to different location in memory, hence causing them to be different.

3 Likes

You could test it before you come here for questions.

From my understanding, cloning the instance would result in two separate instances, one cannot be the same as the other. So the answer is yes, it would only return true at the second index.

However, if you cloned it like

local sound = Instance.new("Sound")
local foo = {sound, sound}

This would return true at indexes one and two, since they are the same instances.

1 Like