Marking Your Places & Models With Attributes and More! (An upcoming Roblox feature)

Hello, hope everyone is feeling great. How long is it going to take for SetAttribute() to be added by Roblox? :thinking:

2 Likes

I think that Roblox’s teams mainly just have other priorities atm but eventually it will definitely be released. There’s a lot of stuff that’s being held back from production at the moment, likely due to a lot of reasons (the ongoing epidemic, backlogs everywhere, server/code performance, avatar and lighting engine updates, etc, etc). There are tons of features I’ve been messing with, and they’re all definitely planned to be finalized but it’s going to be a while is my guess.

Keep in mind that attributes have yet to be announced publicly and are not listed on the roadmap, documented, etc.

2 Likes

Are instance methods considered to be attributes? If so… how would you assign a method as an attribute to achieve Model:Test()?

1 Like

No attributes can’t be directly indexed on the Instance. They’re very similar to Tags. You can use GetAttribute, SetAttribute, GetAttributes, AttributeChanged, and a couple others. They save on the instance like tags, and you can set them to basically any primitive you can think of excluding functions, userdatas (and Instances).

However, you can sort of achieve what you’re trying to do using metatables:

function wrapInstance(custom, instance)
    local wrapped = newproxy(true) -- This creates a userdata you can change the metatable of. There's no way to make typeof return "Instance" without creating a custom typeof
    local meta = getmetatable(wrapped) -- This will get the metatable of the userdata we created
    meta.__index = function(self, index)
        if custom[index] ~= nil and index:sub(1, 2) ~= "__" then
            return custom[index]
        end
        return instance[index]
    end
    meta.__newindex = function(self, index, value)
        local success, err = pcall(function()return instance[index]end)
        if success or not err:find("is not a valid member of") then -- The property exists on the instance or causes a unique error
            instance[index] = value
            return
        end
        if typeof(custom.__newindex) ~= "function" and custom.__newindex then -- Allow the __newindex property of the custom table to be a table or userdata
            custom.__newindex[index] = value
            return
        end
        return custom:__newindex(index, value, instance) -- Call __newindex on the custom table and pass three extra arguments (index, value, and the original instance)
    end
    meta.__call = function(self, ...) -- This used to actually do stuff but recently this functionality was removed because it was unintended behaviour. (It has to do with how Roblox interfaces with lua)
        return instance(...)
    end
    meta.__metatable = getmetatable(instance) -- This returns the "Locked" message
    return wrapped -- Return the wrapped metatable
end

If you call wrapInstance with a table of functions and properties it will return a new userdata which has those functions and properties. Any properties/functions you set with __ at the beginning will be nil when you try to get them on the wrapped instance. You can add a __newindex function on the custom table (not in a metatable) to allow them to set custom properties (or even functions if you want) which will have one extra argument compared to the normal metamethod, the actual instance.

Basically the way it works is it just creates a new userdata to work with and uses metatables to decide what gets returned. It prioritizes things from the custom table, and uses stuff from the instance otherwise.

If you want to talk more I’d suggest doing it through PMs though so this post doesn’t keep getting bumped.

2 Likes

Any updates on when attributes will be released? It’s been a long time since this blog :slight_smile:

1 Like

Well, I have no idea. I’m not too sure the cause of the delay, but, I’m hoping sometime soon as I still have code ready to use them. They’re definitely going to be a huge QOL improvement for me!

1 Like

Is this feature still coming? The api was added over a year ago now and it’s still not enabled https://developer.roblox.com/en-us/resources/release-note/Release-Notes-for-408

3 Likes

Welp, this will make most of my serialization code useless. Yay! Not only this though, but with it you will be able to make serializers better than ever before!

1 Like

Even if having a watermark saying ‘I own this game!’ meant Roblox would take further action, exploiters on other sites would start releasing methods to instantly remove these tags.

All it takes is one exploiter with some developer knowledge to create an automated tag remover and then make it public on one of these off-site exploiter forums.

Personally I think setting attributes as watermarks for your game is a waste of time and Roblox probably won’t ever ban a user for having a watermark attribute that says they don’t own it. If anything setting attributes is just like writing ‘Written by WinterGoons’ at the bottom of a script.

Edit: Didn’t realize this topic was so old. My bad.

since luau, script source is never sent to clients, only luau bytecode, which does not include cmments, and only few exploits can decompile the bytecode to lua code