I don't really want to create anything in specific. I'm simply messing around with scripting and trying out new techniques. An interesting one is the use of metatables for classes. Using things such as self and other cool things to make the code useful...
First, here is what I have so far.
The model hierarchy is as follows: Part, Part\Script and Part\Script\ModuleScript
The script has the following code:
local module = require(script:WaitForChild("ModuleScript"))
local newClass = module.new(script.Parent) -- this would be the brick
newClass:changeColor(BrickColor.new("Really black"))
And the ModuleScript has this code:
local module = {}
module.__index = module -- setting a metamethod
function module.new(brick)
assert(brick:IsA("BasePart"), "parameter must be set to a basepart")
local class = setmetatable({
part = brick;
}, module)
return class
end
function module:changeColor(color)
self.BrickColor = color
end
return module
What I would like it to do is change the color of the brick.. however, I don't think I really understand how this works as nothing happens.
Furthermore, the output doesn't tell me anything so I really can't be sure.
I hope you understand what I'm trying to do and any help towards achieving this would be appreciated.
Yours faithfully, Rod455

1 comment
worth noting I have never done this before and am merely testing... can't seem to fix it though