I’m trying to make a player script and my plan was to have a player class that inherits from a base character class since I plan to have enemies with similar behavior, however, I’ve realized it’s probably more optimal to go with a composition approach. The issue is I’m not sure if what I’m doing is right.
The ControlModule is a torn-down version of the default control module and here’s the rest of the code.
Knit.Start():catch(warn):andThen(function()
require(Modules.PlayerClass)
end)
function PlayerClass.new()
local self = setmetatable({},PlayerClass)
self.trove = Trove.new()
self.input = ControlModule.new()
self.character = BaseCharacter.new()
LocalPlayer.CharacterAdded:Connect(function(character)
self:OnCharacterAdded(character)
end)
LocalPlayer.CharacterRemoving:Connect(function(character)
self:OnCharacterRemoving(character)
end)
if LocalPlayer.Character then
self:OnCharacterAdded(LocalPlayer.Character)
end
return self
end
function BaseCharacter.new(model,health,walkSpeed,jumpHeight,maxJumps)
local self = setmetatable({},BaseCharacter)
self.model = model
self.health = health
self.walkSpeed = walkSpeed
self.jumpHeight = jumpHeight
self.maxJumps = maxJumps
-- For resetting values if they get changed
self.currentJumps = self.maxJumps
self.defaultWalkSpeed = self.walkSpeed
self.defaultJumpHeight = self.jumpHeight
self.defaultHealth = self.health
return self
end