--!optimize 2 --!native --!strict type CharacterSharedFolder = Folder type Character = Model type TCP = RemoteEvent type include = (this: LuaSourceContainer, FunName: string, ...T) -> T local CharacterModule = {} CharacterModule.__index = CharacterModule local RS = game:GetService("RunService") local Storage = game:GetService("ReplicatedStorage") local ClientStorage = Storage:WaitForChild("Client") :: Folder local function client_preprocessor(Character: Character): (include, CharacterSharedFolder) local preprocessor = {} local CharacterShared = Character:WaitForChild("shared") :: CharacterSharedFolder function preprocessor.CharacterShared(): CharacterSharedFolder return CharacterShared end _G.include = function(this: LuaSourceContainer, FunName: string, ...: T) if this:IsDescendantOf(script) then --getfenv is being removed local switch = preprocessor[FunName] return type(switch) == "function" and switch(...) or switch else warn(`Preprocessor append failed "{FunName}"`, debug.traceback()) return nil end end return _G.include, CharacterShared end function CharacterModule.constructor(Character) local _, CharacterShared = client_preprocessor(Character) 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 HumanoidRootPart = Character:WaitForChild("HumanoidRootPart") local Humanoid = Character:WaitForChild("Humanoid") local self = {} self.ActionsTCP = CharacterShared:WaitForChild("Actions") self.ActionsModule = require(script:WaitForChild("Actions")) self.BindModule = require(ClientStorage:WaitForChild("KeyBinds")) self.CurrentCamera = workspace.CurrentCamera self.HRPSettings = HumanoidRPSettings.constructor(HumanoidRootPart) self.CameraConsturctor = CameraModule.constructor(self.CurrentCamera, HumanoidRootPart, Humanoid) self.HumanoidSettings = HumanoidModule.constructor(Humanoid) self.SpineMovement = SpineModule.constructor(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:CharacterKeyBinds() local ClientBindMap = self.BindModule.constructor(false) local Actions = self.ActionsModule.constructor(self.HumanoidSettings, self.CurrentCamera, self.ActionsTCP) --Crouch ClientBindMap:AddInputBegan({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed) Actions:EnableCrouch() end) ClientBindMap:AddInputEnded({Enum.KeyCode.RightControl, Enum.KeyCode.LeftControl}, function(_KeyPressed) Actions:DisableCrouch() end) --Walk ClientBindMap:AddInputBegan({ Enum.KeyCode.LeftAlt, Enum.KeyCode.RightAlt, Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift }, function(_KeyPressed) Actions:EnableSneak() end) ClientBindMap:AddInputEnded({ Enum.KeyCode.LeftAlt, Enum.KeyCode.RightAlt, Enum.KeyCode.LeftShift, Enum.KeyCode.RightShift }, function(_KeyPressed) Actions:DisableSneak() end) --Flashlight ClientBindMap:AddInputBegan({Enum.KeyCode.F}, function(KeyPressed: Enum.KeyCode) Actions:ToggleFlashlight(KeyPressed) end) end function CharacterModule:Crosshair() local RootVelocity = ClientStorage:WaitForChild("RootVelocity") :: BindableEvent local RootVelocityStep = RS.Heartbeat:ConnectParallel(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