Hello guys !
That’s probably a noob lua question, but all the answer I found didn’t make me understood why I got the error : “unknow global self” in the Health() and Stamina() functions.
--!nonstrict
local CommonStats = {}
CommonStats.__index = CommonStats
local function StatSetup(_typeName, _name, _character)
local stat = Instance.new(_typeName)
stat.Name = _name
stat.Parent = _character.Stats
end
function CommonStats.new(_character : Model)
local self = setmetatable({}, CommonStats)
self.character = _character
if _character:FindFirstChild("Stats") == nil then
local stats = Instance.new("Folder")
stats.Name = "Stats"
stats.Parent = _character
end
self.Health = StatSetup("IntValue", "Health", _character)
self.Stamina = StatSetup("IntValue", "Stamina", _character)
return self
end
function CommonStats.Health()
return self.character.Stats.Health
end
function CommonStats.Stamina()
return self.character.Stats.Stamina
end
return CommonStats
Sorry and thanks