Slightly late reply to this great feature, but I just ran into a scenario that begs the question: Why InstanceHandle and not ObjectHandle? It looks like an Object, such as EditableMesh, can’t be referenced by an InstanceHandle; So, other than the datatype name implied restriction, I’m wondering why this limitation exists.
I just released a change enabling this, it should work now.
Fix doesn’t work, will need a revision.
It’s…
Interesting.
I’ve tried it using a LocalScript with a Loader Attribute, but the strange part is that if I do:
const Loader = require(self:GetAttribute("Loader"))
Loader.Run() -- Auto-completed, "Loader" is typeof(Loader).
It will successfully give me auto-completion of the Loader ModuleScript, but this doesn’t work as its trying to require an InstanceHandle!
So I therefore tried:
const Loader = require(self:GetAttribute("Loader"):Wait())
Loader.Run() -- Not auto-completed, "Loader" is shown as an error as its an "unsupported path".
Which now makes the module requiring work but now auto-completion is gone.
This works but it just feels hacky.
const HandleToLoader = script:GetAttribute(`Loader`)
const Loader = require(HandleToLoader:Wait():: typeof(HandleToLoader))
i think you’re a very kind roblox staff can you please become the new roblox ceo
i was about to learn attributes as my next lesion and when came here and i saw lot of people happy, im gonna be motivated unlike with other lesions
Yes, it looks like :Get() and :Wait() don’t carry the types. Only this or the hacky solution earlier carries the type. But this isn’t valid because you can’t pass InstanceHandle to require.
-- has correct intellisense, but will error at runtime
local module = require(script:GetAttribute("module"))
-- no intellisense
module = require(script:GetAttribute("module"):Get())
-- no intellisense
module = require(script:GetAttribute("module"):Wait())
InstanceHandle and Instance Attributes are now available for everyone to use in their experiences. They are no longer limited to Studio, and can now be used in production. Thanks to everyone who tested them and shared feedback during the beta!
We want collections!! Glad this is out though haha
Wicked. I embraced it and broke my live build that way (xD), glad it’s live now!
I’m confused, why has the issue @crusherfire mentioned not been resolved yet? using Instance attributes is deeply discouraged as there’s zero proper type annotation, as attributes as a whole are returned as any.
What if I wanted to link to a “Shared” folder that contains all of my modules? I have to type out the folder structure manually in code, that’s significantly more work than just finding the “Shared” folder directly!
I have a fix for this queued for next week, sorry it took a while because I was occupied with RDC stuff.
cc @vrs2210
Sorry for the wait, requiring through instance refs should now typecheck as expected.
I’m getting odd error logs from this pattern, but they don’t reproduce on my client. Am I missing something?
-- Client
function WorldCharacters.GetNameTagAttachment(character: Model): Attachment?
local handle = character:GetAttribute(Attributes.ATTR_NAME_TAG_ATTACHMENT_REF)
if typeof(handle) ~= "InstanceHandle" then return nil end
local attachment = (handle :: any):Get() -- ReplicatedStorage.Modules.Creatures.WorldCharacters:51: invalid argument #1 (Instance expected, got InstanceHandle)
if attachment == nil or not attachment:IsA("Attachment") or not attachment:IsDescendantOf(character) then
return nil
end
return attachment
end

