✓ Accepted answer
If you wanted to, you could wrap all ROBLOX objects that you want to use in Lua "objects" using a ModuleScript like so:
local PART = {}
PART.__index = PART
function PART.new()
local newpart = {}
setmetatable(newpart, PART)
newpart.obj = Instance.new("Part", workspace)
return newpart
end
function PART.Invisible(this)
if this.obj then
this.obj.Transparency = 1
end
end
return PART
And in another Script...
local PART = require(game:GetService("ServerScriptService").PART)
local part = PART.new()
wait(1)
part:Invisible()
part.obj.BrickColor = BrickColor.new("Bright green")
If you didn't want to supply a reference to the Part itself (which you would do if you want to restrict access to it for whatever reason), you can define the methods in the new function itself:
local PART = {}
function PART.new()
local newpart = {}
local obj = Instance.new("Part", workspace)
function newpart.Invisible()
obj.Transparency = 1
end
return newpart
end
return PART
And in another Script...
local PART = require(game:GetService("ServerScriptService").PART)
local part = PART.new()
wait(1)
part:Invisible()
part.obj.BrickColor = BrickColor.new("Bright green")