Attempt to index function with 'Connect'

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

You assigned self.Trove to a function

I was following what was done in this video : https://www.youtube.com/watch?v=2Msrw5w5cTs

He writes down exactly how I have it written, but for some reason, it isn’t working for me.

You’re missing the parentheses after new

self.Trove = Trove.new()

Oh! I did…

Thanks for pointing that out lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.