FindFirstChild returns weird on userdata

So, don’t ask me why, but I recently faced this weird bug.

I would normally just expect this to error, as an instance is not a string, but it does not.
This happens 100% of the time without fail, the code in the picture is basically the repro, and I’ve been aware of this bug for a very long time now but just now ran into it again and decided to report it.

Nothing much to it really, just weird and out of place to be happening? The ClassName shows it to be pointing to this.

Note: This seems to work with FindFirstChild, WaitForChild, and I believe their other implementations, but directly indexing such as with game[workspace] yields an error.

EDIT: Upon some research with me and my good friend AUSTIN we’ve concluded this is likely caused by a cast in the C++ done to Instance in combo with maybe lua_tostring being called, in which workspace returns the string of Instance, resulting in game:FindFirstChild('Instance') to be what is really being called.
So maybe not a bug but a mis-use of lua_tostring in the background?

It should also be noted that this can be done with other types of userdata, such as Vector3:

local a = Instance.new("Part", game) a.Name = "0, 0, 0" print(game:FindFirstChild(Vector3.new()) == a)
7 Likes

I’ve noticed before that when you pass an instance, it acts as if you did :FindFirstChild("Instance"). Didn’t really look into other data types, but I found it weird that it looked for “Instance” instead of the instance’s Name.

4 Likes