As I’m trying to learn metatables and the proper usage of self, I decided to create my first script that uses some OOP elements. Because of this, I’d like to know if I implemented it properly, or if I’m not using efficiently. Below you may find my localscript code.
local metaTable = {}
metaTable.__index = metaTable
local function setup(character)
local self = setmetatable({}, metaTable)
self.Trove = Trove.new
local humanoid = character:WaitForChild("Humanoid")
self.Trove:Connect(character.ChildAdded, (function(child: Instance)
if child:IsA("Tool") and child.Name == "Tray" then
prompt.Enabled = true; print("equipped")
end
end))
self.Trove:Connect(character.ChildRemoved, (function(child: Instance)
if child:IsA("Tool") and child.Name == "Tray" then
prompt.Enabled = false; print("unequipped")
end
end))
end
if player.Character then
setup(player.Character)
end
player.CharacterAdded:Connect(setup)
Any feedback is most appreciated!