Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script.Parent:WaitForChild("Animate"):Destroy()
- local InputService = game:GetService("UserInputService")
- local Player = game:GetService("Players").LocalPlayer
- local TweenService = game:GetService("TweenService")
- local Camera = workspace.CurrentCamera
- local RunService = game:GetService("RunService")
- local MovementAssets = game:GetService("ReplicatedStorage"):WaitForChild("MovementAssets")
- local Remotes = MovementAssets:WaitForChild("Remotes")
- local HeadMoveRemote = Remotes:WaitForChild("HeadMove")
- local LogSounds = MovementAssets:WaitForChild("Bindables"):WaitForChild("LogSounds")
- local Character = script.Parent
- local Humanoid = Character:WaitForChild("Humanoid")
- --Key Binding--
- local CrouchKey = Enum.KeyCode.LeftControl
- local CrouchKeyToggle = Enum.KeyCode.C
- local SprintKey = Enum.KeyCode.LeftShift
- --Key Binding--
- --Settings--
- local MovementSettings = MovementAssets:WaitForChild("Settings")
- local CanSprint = MovementSettings:WaitForChild("CanSprint")
- --Settings
- --Variables--
- local HumanoidSpeed = 0
- local ClimbSpeed = 0
- local Crouching = false
- local Sprinting = false
- local MoveMode = "Walk"
- --Variables--
- --AnimationTracks--
- local CrouchCurrent = Character.Humanoid:LoadAnimation(script:WaitForChild("CrouchWalk"))
- LogSounds:Fire(Character,CrouchCurrent)
- --AnimationTracks--
- --Head Moving--
- local Head = Character:WaitForChild("Head")
- local Neck = Head:WaitForChild("Neck")
- local Root = Character:WaitForChild("HumanoidRootPart")
- local UpperTorso = Character:WaitForChild("UpperTorso")
- local yOffset = Neck.C0.Y
- HeadMoveRemote:FireServer(_,false)
- spawn(function()
- while RunService.RenderStepped:wait() do
- if Character~=nil then
- local cameraDirection = UpperTorso.CFrame:toObjectSpace(Camera.CFrame).LookVector
- HeadMoveRemote:FireServer(cameraDirection,yOffset,true)
- 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()
- else HeadMoveRemote:FireServer(_,false) break
- end
- end
- end)
- --Head Moving--
- --Animation Handler--
- spawn(function()
- while wait() do
- if Player.Character~=nil and Player.Character:FindFirstChild("Humanoid")~=nil then
- if Crouching then
- if CrouchCurrent.IsPlaying == false then
- CrouchCurrent:Play()
- else
- CrouchCurrent:AdjustSpeed(HumanoidSpeed/4)
- end
- elseif not Crouching then
- CrouchCurrent:Stop()
- end
- else break
- end
- end
- end)
- --Animation Handler--
- Humanoid.WalkSpeed = 8
- Humanoid.Running:Connect(function(Speed)
- HumanoidSpeed = Speed
- end)
- --Toggle Functions--
- function ToggleCrouch()
- if Crouching then
- Crouching = false
- MoveMode = "Walk"
- Humanoid.WalkSpeed = 8
- elseif not Crouching then
- Crouching = true
- MoveMode = "Crouch"
- Humanoid.WalkSpeed = 3
- end
- end
- function ToggleSprint()
- if Sprinting then
- Humanoid.WalkSpeed = 8
- MoveMode = "Walk"
- Sprinting = false
- elseif not Sprinting then
- Humanoid.WalkSpeed = 22
- MoveMode = "Run"
- Sprinting = true
- end
- end
- --Toggle Functions--
- --Input Service--
- InputService.InputBegan:Connect(function(Input,Process)
- if Input.KeyCode == SprintKey and not Crouching and CanSprint.Value then
- Sprinting = false
- ToggleSprint()
- end
- if Input.KeyCode == CrouchKey and not Sprinting and not Process then
- Crouching = false
- ToggleCrouch()
- end
- if Input.KeyCode == CrouchKeyToggle and not Sprinting and not Process then
- ToggleCrouch()
- end
- end)
- InputService.InputEnded:Connect(function(Input,Process)
- if Input.KeyCode == SprintKey and not Crouching then
- Sprinting = true
- ToggleSprint()
- end
- if Input.KeyCode == CrouchKey and not Sprinting then
- Crouching = true
- ToggleCrouch()
- end
- end)
- --Input Service--
- local JumpDelay = 1
- local CanJump = true
- --Animations--
- wait(.2)
- local RunCurrent = Humanoid:LoadAnimation(script:WaitForChild("Run"))
- local WalkCurrent = Humanoid:LoadAnimation(script:WaitForChild("Walk"))
- local IdleCurrent = Humanoid:LoadAnimation(script:WaitForChild("Idle"))
- local JumpCurrent = Humanoid:LoadAnimation(script:WaitForChild("Jump"))
- local FallCurrent = Humanoid:LoadAnimation(script:WaitForChild("Fall"))
- local ClimbCurrent = Humanoid:LoadAnimation(script:WaitForChild("Climb"))
- local ToolHoldCurrent = Humanoid:LoadAnimation(script:WaitForChild("ToolNone"))
- LogSounds:Fire(Character,RunCurrent)
- LogSounds:Fire(Character,WalkCurrent)
- Character.ChildAdded:Connect(function(PotentialTool)
- if PotentialTool:IsA("Tool") and PotentialTool.RequiresHandle then
- ToolHoldCurrent:Play()
- end
- end)
- Character.ChildRemoved:Connect(function(PotentialTool)
- if PotentialTool:IsA("Tool") and PotentialTool.RequiresHandle then
- ToolHoldCurrent:Stop()
- end
- end)
- local Speed = 0
- local State
- wait(.2)
- spawn(function()
- while script~=nil and wait() do
- if Character~=nil and Speed~=nil then
- local CurrentState = Humanoid:GetState()
- if CurrentState == Enum.HumanoidStateType.Climbing then
- WalkCurrent:Stop()
- RunCurrent:Stop()
- CrouchCurrent:Stop()
- FallCurrent:Stop()
- if not ClimbCurrent.IsPlaying then
- ClimbCurrent:Play(.3)
- end
- else
- ClimbCurrent:Stop()
- end
- if CurrentState == Enum.HumanoidStateType.Freefall then
- if RunCurrent.IsPlaying or WalkCurrent.IsPlaying or CrouchCurrent.IsPlaying then
- RunCurrent:Stop()
- WalkCurrent:Stop()
- CrouchCurrent:Stop()
- end
- if not FallCurrent.IsPlaying then
- FallCurrent:Play(.25)
- end
- else
- if FallCurrent.IsPlaying then
- FallCurrent:Stop(.2)
- end
- if CurrentState == Enum.HumanoidStateType.Running then
- if Speed>1 and CurrentState~=Enum.HumanoidStateType.Climbing and CurrentState~=Enum.HumanoidStateType.Seated then
- if not RunCurrent.IsPlaying and MoveMode == "Run" then
- RunCurrent:Play(.3)
- WalkCurrent:Stop()
- CrouchCurrent:Stop()
- end
- if not WalkCurrent.IsPlaying and MoveMode == "Walk" then
- WalkCurrent:Play(.3)
- RunCurrent:Stop()
- CrouchCurrent:Stop()
- end
- if not CrouchCurrent.IsPlaying and MoveMode == "Crouch" then
- CrouchCurrent:Play(.3)
- WalkCurrent:Stop()
- RunCurrent:Stop()
- end
- elseif RunCurrent.IsPlaying or WalkCurrent.IsPlaying then
- RunCurrent:Stop()
- WalkCurrent:Stop()
- end
- end
- end
- if CurrentState == Enum.HumanoidStateType.Jumping and not JumpCurrent.IsPlaying then
- JumpCurrent:Play(.2)
- if FallCurrent.IsPlaying then
- FallCurrent:Stop()
- end
- elseif JumpCurrent.IsPlaying then
- JumpCurrent:Stop(.2)
- end
- ClimbCurrent:AdjustSpeed(ClimbSpeed/8)
- --RunCurrent:AdjustSpeed(Speed/18)
- --WalkCurrent:AdjustSpeed(Speed/12)
- end
- end
- end)
- wait(.2)
- Humanoid.Running:Connect(function(NewSpeed)
- Speed = NewSpeed
- if Speed>1 then
- if IdleCurrent.IsPlaying and MoveMode ~= "Crouch" then
- IdleCurrent:Stop(.3)
- end
- if not RunCurrent.IsPlaying and MoveMode == "Run" then
- RunCurrent:Play(.25)
- WalkCurrent:Stop()
- CrouchCurrent:Stop()
- end
- if not WalkCurrent.IsPlaying and MoveMode == "Walk" then
- WalkCurrent:Play(.25)
- RunCurrent:Stop()
- CrouchCurrent:Stop()
- end
- if MoveMode == "Crouch" and not CrouchCurrent.IsPlaying then
- CrouchCurrent:Play(.25)
- WalkCurrent:Stop()
- RunCurrent:Stop()
- end
- else
- if not IdleCurrent.IsPlaying and not MoveMode == "Crouch" then
- IdleCurrent:Play(.2)
- end
- if RunCurrent.IsPlaying then
- RunCurrent:Stop(.2)
- end
- if WalkCurrent.IsPlaying then
- WalkCurrent:Stop(.2)
- end
- if CrouchCurrent.IsPlaying and not MoveMode == "Crouch" then
- CrouchCurrent:Stop(.2)
- end
- end
- end)
- Humanoid.Climbing:Connect(function(NewSpeed)
- ClimbSpeed = NewSpeed
- end)
- Humanoid.StateChanged:Connect(function(NewState)
- if NewState == Enum.HumanoidStateType.Jumping and not JumpCurrent.IsPlaying then
- JumpCurrent:Play(.2)
- elseif JumpCurrent.IsPlaying then
- JumpCurrent:Stop(.2)
- end
- if NewState == Enum.HumanoidStateType.Jumping and CanJump then
- Humanoid.JumpPower = 0
- CanJump = false ; delay(JumpDelay,function() CanJump = true Humanoid.JumpPower = 50 end)
- end
- end)
- --Animations--
- --Settings--
- CanSprint:GetPropertyChangedSignal("Value"):Connect(function()
- if CanSprint.Value then
- elseif not CanSprint.Value then
- if Sprinting then
- ToggleSprint()
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement