Function to Get Script Identity

As a Roblox developer, it’s currently too hard to detect what identity a script has. As of now, there are two methods:

  • Attempt an action known to require a certain identity and use pcall to detect if it worked or not. This will break if the action attempted has its security level changed (which has happened on multiple occasions).

  • Use a combination of printidentity and LogService to get the actual script identity, print it to the output, and then parse the new message in the output for the identity. This is convoluted, messy, and can be easily broken if another script prints out a similar message at the same time.

There should definitely be a proper function to get the current script identity. printidentity could just be changed to, in addition to its current functionality, return the script’s identity as an int. Or an entirely new getidentity function could be created. Either way, a proper method should definitely exist.

My use case is a module that allows for the creation of special objects, but can also modify the selection behavior of the objects when it’s running in a PluginSecurity identity. Currently I’m having to resort to one of these two bad methods to determine if it can run the selection modification component.

6 Likes

For this specific use case, it might make sense to have something to to see if the current identity has permission X.

if HasPermission"PluginSecurity" then
    -- do stuff when script has plugin security
end

Using the identity to check what permission a script would have issues whenever a new identity is added.

local tbl = {
    true,  -- expessionEval
    false, -- Script
    true,  -- CoreScript
    true,  -- Command Bar, Run Script
    true,  -- Plugin
    true   -- Built In Plugin
}
local function HasPluginSecurity(identity)
    return tbl[identity]
end
1 Like