--!optimize 2 --!native --!strict local RS = game:GetService("RunService") local Storage = game:GetService("ReplicatedStorage") local ClientStorage = Storage:WaitForChild("Client") local BindModule = require(ClientStorage:WaitForChild("KeyBinds")) local HumanoidRPSettings = require(script:WaitForChild("HumanoidRootPart")) local CameraModule = require(script:WaitForChild("Camera")) local HumanoidModule = require(script:WaitForChild("Humanoid")) local SpineModule = require(script:WaitForChild("SpineKinematics")) local ActionsModule = require(script:WaitForChild("Actions")) type Character = Model type HumanoidRootPart = BasePart type TCP = RemoteEvent type CurrentCamera = Camera type CharacterShared = Folder type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type Impl_Constructor = { __index: Impl_Constructor, constructor: Constructor_Fun, --Class functions Spawned: (self: ClassConstructor) -> (), CharacterKeyBinds: (self: ClassConstructor) -> (), Crosshair: (self: ClassConstructor) -> RBXScriptConnection, SetWalkSpeed: (self: ClassConstructor) -> (), SetJumpHeight: (self: ClassConstructor) -> (), DisableRobloxSounds: (self: ClassConstructor) -> (), EnableCameraBobbing: (self: ClassConstructor) -> (), EnableSpineMovement: (self: ClassConstructor) -> () } & Impl_Static_Props type Impl_Static_Props = { KeyBinds: { Crouch: {Enum.KeyCode}, Walk: {Enum.KeyCode}, Flashlight: {Enum.KeyCode} } } type Constructor_Fun = (Character: Character) -> ClassConstructor type Constructor_Return_Props = { CharacterShared: CharacterShared, ActionsTCP: TCP, CurrentCamera: CurrentCamera, HRPSettings: HumanoidRPSettings.HumanoidRPSettingsConstructor, CameraConsturctor: CameraModule.CameraConstructor, HumanoidSettings: HumanoidModule.HumanoidConstructor, SpineMovement: SpineModule.SpineConstructor } local CharacterModule = {} :: Impl_Constructor CharacterModule.__index = CharacterModule CharacterModule.KeyBinds = { Crouch = { Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl }, Walk = { Enum.KeyCode.LeftAlt, Enum.KeyCode.RightAlt, Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift }, Flashlight = { Enum.KeyCode.F } } function CharacterModule.constructor(Character) local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") :: HumanoidRootPart local Humanoid = Character:WaitForChild("Humanoid") :: Humanoid local self = {} :: Constructor_Return_Props self.CharacterShared = Character:WaitForChild("shared") :: Folder self.CurrentCamera = workspace.CurrentCamera self.ActionsTCP = self.CharacterShared:WaitForChild("Actions") :: TCP self.HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart) self.CameraConsturctor = CameraModule.constructor(self.CurrentCamera, HumanoidRootPart, Humanoid) self.HumanoidSettings = HumanoidModule.constructor(Humanoid) self.SpineMovement = SpineModule.constructor(self.CharacterShared, self.CurrentCamera) pcall(table.clear, _G) pcall(table.freeze, _G) pcall(table.clear, shared) pcall(table.freeze, shared) return setmetatable(self, CharacterModule) end function CharacterModule:Spawned() self.SpineMovement = SpineModule.constructor(self.CharacterShared, self.CurrentCamera) end function CharacterModule:CharacterKeyBinds() local ClientBindMap = BindModule.constructor(false) local Actions = ActionsModule.constructor(self.CharacterShared, self.HumanoidSettings, self.CurrentCamera, self.ActionsTCP) --Crouch ClientBindMap:AddInputBegan(CharacterModule.KeyBinds.Crouch, function(_KeyPressed) Actions:EnableCrouch() end) ClientBindMap:AddInputEnded(CharacterModule.KeyBinds.Crouch, function(_KeyPressed) Actions:DisableCrouch() end) --Walk ClientBindMap:AddInputBegan(CharacterModule.KeyBinds.Walk, function(_KeyPressed) Actions:EnableSneak() end) ClientBindMap:AddInputEnded(CharacterModule.KeyBinds.Walk, function(_KeyPressed) Actions:DisableSneak() end) --Flashlight ClientBindMap:AddInputBegan(CharacterModule.KeyBinds.Flashlight, function(KeyPressed) Actions:ToggleFlashlight(KeyPressed) end) end function CharacterModule:Crosshair() local RootVelocity = ClientStorage:WaitForChild("RootVelocity") :: BindableEvent local RootVelocityStep = RS.Heartbeat:Connect(function(_dt) RootVelocity:Fire(self.HRPSettings:Velocity()) end) return RootVelocityStep end function CharacterModule:SetWalkSpeed() self.HumanoidSettings:SetWalkSpeed() end function CharacterModule:SetJumpHeight() self.HumanoidSettings:SetJumpHeight() end function CharacterModule:DisableRobloxSounds() self.HRPSettings:DisableRobloxSounds() end function CharacterModule:EnableCameraBobbing() self.CameraConsturctor:EnableBobbing() end function CharacterModule:EnableSpineMovement() self.SpineMovement:Enable() end return CharacterModule