Object oriented programming having an error with specific function name

So I am busy with oop and I have this error:

  15:13:21.320 - ServerScriptService.Script:5: attempt to call a number value

Here is the script:

local Family = {}
Family.__index = Family

Family.Died = Instance.new("BindableEvent")

function Family.new(Name)
	local Human = {}
	Human.Name = Name
	Human.Age = 0
	Human.Gender = math.random(1,2)
	setmetatable(Human, Family)
	return Human

function Family:Age()
	print("E")--for testing obviously

return Family

Normal script:

local Family = require(game.ServerStorage:WaitForChild("Family"))

local Child = Family.new("Tristan")

Child:Age()--error happens here.

For some reason when I use :Age() it doesn’t work but when I use something else it works.

I THINK when you do :Age it is indexing the .Age in family, not the function… so you are trying to call the number Human.Age = 0 and not Family:Age(), you said if you use other function names, it works?

1 Like