How to get the instance's hexadecimal reference

I am trying to get the instance’s hexadecimal reference in memory, however I don’t know how to access it. I know that when you set the key of a dictionary as an object it will use the hexadecimal reference as the key in string form, however I don’t know how I access that string.

2 Likes

See solution to this similar post.

Reminder that we have no real memory access methods in ROBLOX. Don’t know why you would be trying to access this – if you’re looking to use it as a unique identifier, just use HttpService:GenerateGUID().

3 Likes

I’m creating a state manager to keep track of player’s states, and I want to make it so we can easily access a character’s states, the issue with using char.Name is that if we have NPC with the same name it will have reference issues.

1 Like

There is a function for it called :GetDebugId() but it’s locked to context level 3 I believe

1 Like

Player as in NPC or actual character?
You shouldn’t be using keys that are at risk of being the same to track data for unique instances. You’re just asking for problems like these.

If it’s for an NPC, use a GUID anyways instead of a name as a reference. Practically zero chance of collision (use two if you are truly paranoid, or combine it with something like os.time() for more separation). Alternatively, you can use some sort of hashing algorithm to generate unique keys for every character’s state.

If it’s an actual player, just use their UserId, which is gauranteed to be unique per-player.

1 Like

Just use the Player/Character instance directly as the key. You will have to make sure it is removed from the hashmap when the player is destroyed, though, since instances won’t GC if they are referenced as keys regardless of the table’s mode.

3 Likes

Do this, the Instance object itself is unique and thus a good key.

1 Like

That’s what I been doing, as the key, but I need a unique name for the character’s folder I was trying to use the key as the folder but couldnt