Hello everyone, I’m making crouch system. I use two animations first animation when the player is crouched and does nothing and the other when the player moves. Right now the problem is happening with the walking animation. When the player moves the animation jerks and it looks very strange. Here is the video and script:
local KeyBind = "LeftControl"
local UIS = game:GetService("UserInputService")
local Tween = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = script:WaitForChild("CrouchIdle")
local Animation2 = script:WaitForChild("CrouchWalk")
local TrackAnim = Humanoid:LoadAnimation(Animation)
local TrackAnim2 = Humanoid:LoadAnimation(Animation2)
TrackAnim.Looped = true
TrackAnim2.Looped = true
local Crouching = false
UIS.InputBegan:Connect(function(Input, GPE)
if GPE then return end
if Input.KeyCode == Enum.KeyCode[KeyBind] then
if Crouching then
Humanoid.WalkSpeed = 8
Crouching = false
Character:WaitForChild("HumanoidRootPart").CanCollide = true
Tween:Create(Character:WaitForChild("Humanoid"), TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, 0, 0)}):Play()
script.Parent:WaitForChild("Sprint").Enabled = true
TrackAnim:Stop()
else
Humanoid.WalkSpeed = 5
Crouching = true
Character:WaitForChild("HumanoidRootPart").CanCollide = false
Tween:Create(Character:WaitForChild("Humanoid"), TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, -1.75, 0)}):Play()
script.Parent:WaitForChild("Sprint").Enabled = false
Tween:Create(game.Players.LocalPlayer.Character.Humanoid, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {WalkSpeed = 5}):Play()
Tween:Create(workspace.CurrentCamera, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {FieldOfView = 70}):Play()
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
if Humanoid.MoveDirection.Magnitude > 0 and Crouching == true then
TrackAnim2:Play()
else
TrackAnim2:Stop()
end
end)
TrackAnim:Play()
TrackAnim:AdjustSpeed(0.8)
end
end
end)
Maybe the 2 animations (your own walk anim and robloxs default walk anim) are blending in together? if it is, try Adjusting The Weight and chaging the Animation Priority to Movement.
I did it but there are some couple bugs. (also og walk og run, oganimation1 and oganimation2 original anims. oganimation1 is animation1 under idle inside the animate script and oganimation2 is animation 2 under idle.)
local KeyBind = "LeftControl"
local UIS = game:GetService("UserInputService")
local Tween = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Animate = Character:WaitForChild("Animate")
local Humanoid = Character:WaitForChild("Humanoid")
local Animation = script:WaitForChild("CrouchIdle")
local Animation2 = script:WaitForChild("CrouchWalk")
local OgWalk = script:WaitForChild("OgWalk")
local OgRun = script:WaitForChild("OgRun")
local TrackAnim = Humanoid:LoadAnimation(Animation)
local TrackAnim2 = Humanoid:LoadAnimation(Animation2)
TrackAnim.Looped = true
TrackAnim2.Looped = true
local Crouching = false
UIS.InputBegan:Connect(function(Input, GPE)
if GPE then return end
if Input.KeyCode == Enum.KeyCode[KeyBind] then
if Crouching then
Animate.idle.Animation1.AnimationId = script.OgAnimation1.AnimationId
Animate.idle.Animation2.AnimationId = script.OgAnimation2.AnimationId
Animate.run.RunAnim.AnimationId = OgRun.AnimationId
Animate.walk.WalkAnim.AnimationId = OgWalk.AnimationId
Humanoid.WalkSpeed = 8
Crouching = false
Character:WaitForChild("HumanoidRootPart").CanCollide = true
Tween:Create(Character:WaitForChild("Humanoid"), TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, 0, 0)}):Play()
else
Animate.idle.Animation1.AnimationId = Animation.AnimationId
Animate.idle.Animation2.AnimationId = Animation.AnimationId
Animate.run.RunAnim.AnimationId = Animation2.AnimationId
Animate.walk.WalkAnim.AnimationId = Animation2.AnimationId
Humanoid.WalkSpeed = 5
Crouching = true
Character:WaitForChild("HumanoidRootPart").CanCollide = false
Tween:Create(Character:WaitForChild("Humanoid"), TweenInfo.new(0.3, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {CameraOffset = Vector3.new(0, -1.75, 0)}):Play()
Tween:Create(game.Players.LocalPlayer.Character.Humanoid, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out), {WalkSpeed = 5}):Play()
Tween:Create(workspace.CurrentCamera, TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out), {FieldOfView = 70}):Play()
TrackAnim:AdjustSpeed(0.8)
end
end
end)