--[[
Checks if a property is read-only for a standard script
@param className string
@param propertyName string
@return boolean?
]]
local function isPropertyReadOnly(className: string, propertyName: string): boolean?
local properties = ReflectionService:GetPropertiesOfClass(className, {
Security = allCapabilities
})
if not properties then
warn(`Class {className} not found.`)
return nil
end
for _, propInfo in properties do
if propInfo.Name == propertyName then
local writePermit = propInfo.Permits.Write
-- It is read-only ONLY if the permit exists (not nil)
-- AND that permit is not 0 (not "None").
return writePermit ~= nil and writePermit ~= 0
end
end
warn(`Property '{propertyName}' not found on class '{className}'`)
return nil
end
What’s the proper way to determine if a property is read-only via ReflectionService?
I have an idea of using pcall to try and change the value of every property, and in catch part you define that one as read only because catch part will catch the error (Trying to change value in a read only property).
local reflectionService = game:GetService('ReflectionService')
local data = reflectionService:GetPropertiesOfClass(class)
for _,p in data do
if p.Permits.Read and p.Display.Category ~= 'Permissions' and not p.Display.DeprecationMessage then
if p.Permits.Write then
-- Writable
else
-- Read-Only
end
end
end
Note that this will still include some properties that should be Hidden. I’ve created a list of Hidden properties, but there are still properties in that list of which shouldn’t be Hidden. I generated the list from the Roblox API dump.
Unfortunately, it looks like there won’t be a native solution for a long while. So a manual list will be needed until then: