AttributeBridge, A great way to use dynamically switch between Attribute and Value

Introduction

I recently ran into an issue where my team member can’t turn on Attribute on their studio.

So I came up with AttributeBridge, very simple modules that switch to Attribute when it’s available, and fall back to regular StringValue/IntValue/etc if it wasn’t available.

https://gist.github.com/Pnlmon/666a5f681702c46ba5dd98923b4b61f6

Overview:

Bridge:GetAttribute(Name, Object)

Return the desired Attribute from the Object

Bridge:SetAttribute(Name, Object, SetValue)

Set the Attribute onto an Object with the value given in SetValue

6 Likes

Simple and effective, I’d just recommend you concatenate something like “attribute_” to the instance names to avoid weird bugs due to instance name conflicts. That way, you can also add a BindToAttributeChange method by checking if an added child has “attribute_” in the name.

2 Likes

That’s actually an interesting suggestion, I’ve updated the code to use the “attribute_” prefix

2 Likes