What is an InstanceHandle?

I have a modulescript (A) with a “Generator” Instance Attribute set to another modulescript (B). This is the code i am running in the first modulescript (A):

local GeneratorModule = script:GetAttribute("Generator")
print(typeof(GeneratorModule)) --Should be "Instance", is actually "InstanceHandle"

I would expect this to print “Instance”, but i am instead being met with “InstanceHandle”
Attempting to require the “InstanceHandle” results in an error as it isnt a valid type for require.

Ive searched the engine documentation and i cant find anything about “InstanceHandle”

What is this “InstanceHandle” type and how can i instead get the actual instance?

1 Like

In the announcement post its mentioned that you need to use :Get() on the InstanceHandle to get the instance. So just do GeneratorModule:Get() to get the actual instance.

3 Likes

Any idea why its not included in the documentation at all?

2 Likes

Haven’t checked the documentation myself, but I would assume since its a new attribute they probably just forgot to do it.

4 Likes

This is new Instance Attributes feature that was just released in the recent studio update. When you set an attribute to an Instance, roblox now returns an InstanceHandle (safe pointer/wrapper) instead of the raw Instance to prevent errors with StreamingEnabled if the target instance hasn’t loaded yet

To get the actual ModuleScript you need to use :Get() or :Wait() method on that handle

1 Like

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