I’ve been trying to figure out OOP for some a few hours now, and just as I thought I was getting the concept, the script errors out. Why is this the case, and what did I do wrong?
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local stove = workspace:WaitForChild("Stove1")
local interactPart = stove:WaitForChild("InteractPart")
local prompt = interactPart:WaitForChild("ProximityPrompt")
local Trove = require(game:GetService("ReplicatedStorage").Packages.Trove)
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)
function metaTable:Destroy()
self.Trove:Destroy()
end