This is a simple script that returns a function you can call to get an instance’s property without interacting with LuaBridge. Used in Liquid Breakout 1.15.3.
What this script is designed for:
- Quickly referencing properties of services or static instances
- Convenience and reusability
- A starting point to learn about optimization
What this script is not designed for:
- Hot or rarely-used properties
- Ultra-performant loops
- Properties that aren’t guaranteed to fire change events such as
BasePart.CFrameorBone.Transform
Make sure this is first required by a script that will never be deleted. See PSA: ModuleScripts and RBXScriptSignals don't work together exactly how you'd expect for details.
This script is unlicensed and is in the public domain.
-- GetPropertyCacheable.luau
-- Simple property fetcher with caching and automatic signal management
-- LB-OFT Engine 5.0
-- Contrastual, 2026
--[[
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
]]
local cachedProperties = {}
local uniqueKey = {} -- prevents garbage data attacks
-- Get a function that returns a cache of the instance's property.
-- Not recommended for physics properties such as <code>BasePart.CFrame</code>.
local function getPropertyCacheable(instance: Instance, property: string): () -> any
local properties = cachedProperties[instance]
if not properties then
properties = {}
cachedProperties[instance] = properties
end
if not properties[uniqueKey] then
properties[uniqueKey] = instance.Destroying:Connect(function()
for k, v in properties do
if k == uniqueKey then continue end
v[2]:Disconnect()
end
properties[uniqueKey] = nil
end)
end
local propData = properties[property]
if propData then
return propData[1]
end
local prop = instance[property]
local function get()
return prop
end
propData = {get, instance:GetPropertyChangedSignal(property):Connect(function()
prop = instance[property]
end)}
return get
end
return getPropertyCacheable