Problem with type checking metatable

I have just learned OOP and type checking for like a month. I’m kind of new to it and having a problem…

Problem
So, i created a type checking module script (placed in replicated storage)
The issue is when i type --!strict, my main script (separate from the type checking script) appears this bug:
Capture

What i have tried
I have tried to ask ChatGPT for solution… But seems it doesn’t help my problem.
I thought i have figured out from a post i saw from dev forum but seems the problem still there…
Here is that post link: Guide to Type-Checking with OOP - Resources / Community Tutorials - Developer Forum | Roblox

Here is my type checking script:

local types = {}

export type animatronic = {
	Connection: RBXScriptConnection?,
	Char: Model?,
	Name: string,
	AiNumber: number,
	DoorRoute: string,

	--//Methods
	New: (char, AiNumber, DoorRoute, TotalRoute) -> (),
	Decide: (self) -> (number),
	Static: (self, bool: boolean) -> (),
	Jumpscare: (self) -> ()
} & any & typeof(setmetatable({}::self ,animatronic))

export type Foxy = {
	self: typeof(setmetatable({}::self ,Foxy)),
	foxyMinigameDuration: number,
	foxyAttack: boolean,
	SystemCountRequire: number,
	PlayerCount: IntValue?, 

	--//Methods//--
	New: (char, AiNumber, DoorRoute, TotalRoute) -> (),
	_RandomPlushie: (self, number) -> (), 
	Attack: (self) -> (),
	Move: (self) -> (),
	CreateMove: (self) -> ()
} & animatronic

return types

Thank you for reading, I’m really bad at this :sob: .
Appreciate any comment! (sorry for my English skill) tell me if you need more information.
If you have any docs or posts that may help, it would be absolute awesome!!

Can you show us the entire setmetatable line?

Also, I assume that BaseAnimatronic is of type animatronic, correct? If that is the case, I suspect that the issue is that the New method in the class is specified as returning nothing because of the empty brackets after the arrow (...) -> (). You should add the return type in those brackets if it returns something.

1 Like

Here is the script that contain bug:

--// Module Scripts
local BaseAnimatronic = require(script.Parent)

local Foxy = {}
Foxy.__index = Foxy
setmetatable(Foxy, BaseAnimatronic)

--// Initialization
function Foxy.New(char, AiNumber, DoorRoute, TotalRoute): AnimatronicTypes.Foxy
	local self = setmetatable(BaseAnimatronic.New(char, AiNumber, DoorRoute, TotalRoute), Foxy)
	self.foxyMinigameDuration = 60
	self.foxyAttack = false

	--// Player-related variables
	self.SystemCountRequire = 0
	self.PlayerCount = ServerScriptService.Settings:WaitForChild("counterNum")

	return self
end

Here is the script which called BaseAnimatronic (The one contains New function):

local AiMovement = {}
AiMovement.__index = AiMovement

function AiMovement.New(char, AiNumber, DoorRoute, TotalRoute): AnimatronicTypes.animatronic
	local self = setmetatable({}, AiMovement) :: AnimatronicTypes.animatronic
	self.Connection = nil
	self.Char = char
	self.Name = char.Name
	self.AiNumber = AiNumber
	self.DoorRoute = DoorRoute
	return self
end

Its like returning a table ig, the “new” method or function (idk what it called._.).