Advertisement
KOLBYsssss

MovementSystemCharacter Local script

Feb 25th, 2023
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.63 KB | None | 0 0
  1. script.Parent:WaitForChild("Animate"):Destroy()
  2.  
  3. local InputService = game:GetService("UserInputService")
  4. local Player = game:GetService("Players").LocalPlayer
  5. local TweenService = game:GetService("TweenService")
  6. local Camera = workspace.CurrentCamera
  7. local RunService = game:GetService("RunService")
  8. local MovementAssets = game:GetService("ReplicatedStorage"):WaitForChild("MovementAssets")
  9. local Remotes = MovementAssets:WaitForChild("Remotes")
  10. local HeadMoveRemote = Remotes:WaitForChild("HeadMove")
  11. local LogSounds = MovementAssets:WaitForChild("Bindables"):WaitForChild("LogSounds")
  12.  
  13.  
  14. local Character = script.Parent
  15. local Humanoid = Character:WaitForChild("Humanoid")
  16.  
  17. --Key Binding--
  18. local CrouchKey = Enum.KeyCode.LeftControl
  19. local CrouchKeyToggle = Enum.KeyCode.C
  20.  
  21. local SprintKey = Enum.KeyCode.LeftShift
  22. --Key Binding--
  23.  
  24. --Settings--
  25. local MovementSettings = MovementAssets:WaitForChild("Settings")
  26.  
  27. local CanSprint = MovementSettings:WaitForChild("CanSprint")
  28. --Settings
  29.  
  30.  
  31. --Variables--
  32. local HumanoidSpeed = 0
  33. local ClimbSpeed = 0
  34. local Crouching = false
  35. local Sprinting = false
  36. local MoveMode = "Walk"
  37. --Variables--
  38.  
  39.  
  40. --AnimationTracks--
  41. local CrouchCurrent = Character.Humanoid:LoadAnimation(script:WaitForChild("CrouchWalk"))
  42. LogSounds:Fire(Character,CrouchCurrent)
  43. --AnimationTracks--
  44.  
  45. --Head Moving--
  46.  
  47. local Head = Character:WaitForChild("Head")
  48. local Neck = Head:WaitForChild("Neck")
  49. local Root = Character:WaitForChild("HumanoidRootPart")
  50. local UpperTorso = Character:WaitForChild("UpperTorso")
  51. local yOffset = Neck.C0.Y
  52. HeadMoveRemote:FireServer(_,false)
  53.  
  54.  
  55. spawn(function()
  56. while RunService.RenderStepped:wait() do
  57. if Character~=nil then
  58. local cameraDirection = UpperTorso.CFrame:toObjectSpace(Camera.CFrame).LookVector
  59. HeadMoveRemote:FireServer(cameraDirection,yOffset,true)
  60. TweenService:Create(Neck,TweenInfo.new(.4),{C0 = CFrame.new(0, yOffset, 0) * CFrame.Angles(0, -math.asin(cameraDirection.x/1.2), 0) * CFrame.Angles(math.asin(cameraDirection.y/2), 0, 0)}):Play()
  61. else HeadMoveRemote:FireServer(_,false) break
  62. end
  63. end
  64. end)
  65.  
  66.  
  67.  
  68. --Head Moving--
  69.  
  70.  
  71. --Animation Handler--
  72. spawn(function()
  73. while wait() do
  74. if Player.Character~=nil and Player.Character:FindFirstChild("Humanoid")~=nil then
  75.  
  76. if Crouching then
  77. if CrouchCurrent.IsPlaying == false then
  78. CrouchCurrent:Play()
  79. else
  80. CrouchCurrent:AdjustSpeed(HumanoidSpeed/4)
  81. end
  82. elseif not Crouching then
  83. CrouchCurrent:Stop()
  84. end
  85.  
  86.  
  87. else break
  88. end
  89. end
  90. end)
  91.  
  92.  
  93. --Animation Handler--
  94. Humanoid.WalkSpeed = 8
  95. Humanoid.Running:Connect(function(Speed)
  96. HumanoidSpeed = Speed
  97. end)
  98.  
  99.  
  100.  
  101. --Toggle Functions--
  102. function ToggleCrouch()
  103. if Crouching then
  104. Crouching = false
  105. MoveMode = "Walk"
  106. Humanoid.WalkSpeed = 8
  107. elseif not Crouching then
  108. Crouching = true
  109. MoveMode = "Crouch"
  110. Humanoid.WalkSpeed = 3
  111. end
  112. end
  113.  
  114. function ToggleSprint()
  115. if Sprinting then
  116. Humanoid.WalkSpeed = 8
  117. MoveMode = "Walk"
  118. Sprinting = false
  119. elseif not Sprinting then
  120. Humanoid.WalkSpeed = 22
  121. MoveMode = "Run"
  122. Sprinting = true
  123. end
  124. end
  125.  
  126.  
  127.  
  128. --Toggle Functions--
  129.  
  130.  
  131.  
  132.  
  133.  
  134. --Input Service--
  135. InputService.InputBegan:Connect(function(Input,Process)
  136. if Input.KeyCode == SprintKey and not Crouching and CanSprint.Value then
  137. Sprinting = false
  138. ToggleSprint()
  139. end
  140.  
  141. if Input.KeyCode == CrouchKey and not Sprinting and not Process then
  142. Crouching = false
  143. ToggleCrouch()
  144. end
  145.  
  146. if Input.KeyCode == CrouchKeyToggle and not Sprinting and not Process then
  147. ToggleCrouch()
  148. end
  149.  
  150.  
  151.  
  152. end)
  153.  
  154.  
  155. InputService.InputEnded:Connect(function(Input,Process)
  156. if Input.KeyCode == SprintKey and not Crouching then
  157. Sprinting = true
  158. ToggleSprint()
  159. end
  160.  
  161. if Input.KeyCode == CrouchKey and not Sprinting then
  162. Crouching = true
  163. ToggleCrouch()
  164. end
  165.  
  166. end)
  167. --Input Service--
  168.  
  169. local JumpDelay = 1
  170. local CanJump = true
  171.  
  172. --Animations--
  173. wait(.2)
  174. local RunCurrent = Humanoid:LoadAnimation(script:WaitForChild("Run"))
  175. local WalkCurrent = Humanoid:LoadAnimation(script:WaitForChild("Walk"))
  176. local IdleCurrent = Humanoid:LoadAnimation(script:WaitForChild("Idle"))
  177. local JumpCurrent = Humanoid:LoadAnimation(script:WaitForChild("Jump"))
  178. local FallCurrent = Humanoid:LoadAnimation(script:WaitForChild("Fall"))
  179. local ClimbCurrent = Humanoid:LoadAnimation(script:WaitForChild("Climb"))
  180. local ToolHoldCurrent = Humanoid:LoadAnimation(script:WaitForChild("ToolNone"))
  181.  
  182.  
  183. LogSounds:Fire(Character,RunCurrent)
  184. LogSounds:Fire(Character,WalkCurrent)
  185.  
  186. Character.ChildAdded:Connect(function(PotentialTool)
  187. if PotentialTool:IsA("Tool") and PotentialTool.RequiresHandle then
  188. ToolHoldCurrent:Play()
  189. end
  190. end)
  191.  
  192. Character.ChildRemoved:Connect(function(PotentialTool)
  193. if PotentialTool:IsA("Tool") and PotentialTool.RequiresHandle then
  194. ToolHoldCurrent:Stop()
  195. end
  196. end)
  197.  
  198. local Speed = 0
  199.  
  200. local State
  201.  
  202. wait(.2)
  203. spawn(function()
  204. while script~=nil and wait() do
  205. if Character~=nil and Speed~=nil then
  206. local CurrentState = Humanoid:GetState()
  207.  
  208. if CurrentState == Enum.HumanoidStateType.Climbing then
  209.  
  210. WalkCurrent:Stop()
  211. RunCurrent:Stop()
  212. CrouchCurrent:Stop()
  213.  
  214. FallCurrent:Stop()
  215. if not ClimbCurrent.IsPlaying then
  216. ClimbCurrent:Play(.3)
  217. end
  218. else
  219. ClimbCurrent:Stop()
  220. end
  221.  
  222. if CurrentState == Enum.HumanoidStateType.Freefall then
  223. if RunCurrent.IsPlaying or WalkCurrent.IsPlaying or CrouchCurrent.IsPlaying then
  224. RunCurrent:Stop()
  225. WalkCurrent:Stop()
  226. CrouchCurrent:Stop()
  227. end
  228.  
  229. if not FallCurrent.IsPlaying then
  230. FallCurrent:Play(.25)
  231. end
  232.  
  233.  
  234. else
  235.  
  236. if FallCurrent.IsPlaying then
  237. FallCurrent:Stop(.2)
  238. end
  239.  
  240. if CurrentState == Enum.HumanoidStateType.Running then
  241. if Speed>1 and CurrentState~=Enum.HumanoidStateType.Climbing and CurrentState~=Enum.HumanoidStateType.Seated then
  242. if not RunCurrent.IsPlaying and MoveMode == "Run" then
  243. RunCurrent:Play(.3)
  244. WalkCurrent:Stop()
  245. CrouchCurrent:Stop()
  246. end
  247.  
  248. if not WalkCurrent.IsPlaying and MoveMode == "Walk" then
  249. WalkCurrent:Play(.3)
  250. RunCurrent:Stop()
  251. CrouchCurrent:Stop()
  252. end
  253.  
  254. if not CrouchCurrent.IsPlaying and MoveMode == "Crouch" then
  255. CrouchCurrent:Play(.3)
  256. WalkCurrent:Stop()
  257. RunCurrent:Stop()
  258. end
  259.  
  260.  
  261. elseif RunCurrent.IsPlaying or WalkCurrent.IsPlaying then
  262. RunCurrent:Stop()
  263. WalkCurrent:Stop()
  264. end
  265. end
  266.  
  267.  
  268.  
  269.  
  270.  
  271. end
  272.  
  273. if CurrentState == Enum.HumanoidStateType.Jumping and not JumpCurrent.IsPlaying then
  274. JumpCurrent:Play(.2)
  275.  
  276. if FallCurrent.IsPlaying then
  277. FallCurrent:Stop()
  278. end
  279.  
  280. elseif JumpCurrent.IsPlaying then
  281. JumpCurrent:Stop(.2)
  282. end
  283.  
  284. ClimbCurrent:AdjustSpeed(ClimbSpeed/8)
  285. --RunCurrent:AdjustSpeed(Speed/18)
  286. --WalkCurrent:AdjustSpeed(Speed/12)
  287.  
  288. end
  289. end
  290. end)
  291.  
  292. wait(.2)
  293. Humanoid.Running:Connect(function(NewSpeed)
  294. Speed = NewSpeed
  295. if Speed>1 then
  296.  
  297. if IdleCurrent.IsPlaying and MoveMode ~= "Crouch" then
  298. IdleCurrent:Stop(.3)
  299. end
  300.  
  301. if not RunCurrent.IsPlaying and MoveMode == "Run" then
  302. RunCurrent:Play(.25)
  303. WalkCurrent:Stop()
  304. CrouchCurrent:Stop()
  305. end
  306.  
  307. if not WalkCurrent.IsPlaying and MoveMode == "Walk" then
  308. WalkCurrent:Play(.25)
  309. RunCurrent:Stop()
  310. CrouchCurrent:Stop()
  311. end
  312.  
  313. if MoveMode == "Crouch" and not CrouchCurrent.IsPlaying then
  314. CrouchCurrent:Play(.25)
  315. WalkCurrent:Stop()
  316. RunCurrent:Stop()
  317. end
  318.  
  319.  
  320.  
  321. else
  322.  
  323. if not IdleCurrent.IsPlaying and not MoveMode == "Crouch" then
  324. IdleCurrent:Play(.2)
  325. end
  326.  
  327. if RunCurrent.IsPlaying then
  328. RunCurrent:Stop(.2)
  329. end
  330.  
  331. if WalkCurrent.IsPlaying then
  332. WalkCurrent:Stop(.2)
  333. end
  334.  
  335. if CrouchCurrent.IsPlaying and not MoveMode == "Crouch" then
  336. CrouchCurrent:Stop(.2)
  337. end
  338.  
  339. end
  340. end)
  341.  
  342. Humanoid.Climbing:Connect(function(NewSpeed)
  343. ClimbSpeed = NewSpeed
  344. end)
  345.  
  346.  
  347. Humanoid.StateChanged:Connect(function(NewState)
  348.  
  349. if NewState == Enum.HumanoidStateType.Jumping and not JumpCurrent.IsPlaying then
  350. JumpCurrent:Play(.2)
  351. elseif JumpCurrent.IsPlaying then
  352. JumpCurrent:Stop(.2)
  353. end
  354. if NewState == Enum.HumanoidStateType.Jumping and CanJump then
  355. Humanoid.JumpPower = 0
  356. CanJump = false ; delay(JumpDelay,function() CanJump = true Humanoid.JumpPower = 50 end)
  357. end
  358.  
  359. end)
  360.  
  361. --Animations--
  362.  
  363. --Settings--
  364. CanSprint:GetPropertyChangedSignal("Value"):Connect(function()
  365. if CanSprint.Value then
  366. elseif not CanSprint.Value then
  367.  
  368. if Sprinting then
  369. ToggleSprint()
  370. end
  371.  
  372. end
  373. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement