How does composition work?

I’m planning to make AI that can basically do anything the player can do the only obvious difference is it’s not controlled by a player instead I’m going to use a behavior tree and I wanna use composition to do this neatly.

My current plan is going to be to make 3 classes (module scripts) a character class that will set up everything they have in common methods, states, health, walk speed, etc. Then a player class will probably just handle input, and then the AI class which will control the behavior tree.

The issue though is I don’t think this is how composition works so what would be the proper way to go about doing this?

Edit: if I’m understanding this correctly essentially what I need to do is isolate the needed behavior into its own class and then add then I can just add that behavior to any class that needs it?

yes you are doing it right, you just stick stuff inside other stuff and redo the functions on the outside if needed. I like to use ._Inner to reference the main component.

local Entity = {}
-- ...
function Entity:Attack(dmg: number) end
-- ...

local Player = {}
Player.__index = Player
function number)
    local self = setmetatable({}, Player)
    self._Inner =
    return self

function Player:Attack()

local Zombie = {}
-- same as above

function Zombie:Attack()