I've been working with trying to get a walking crouch script to work but I can't get players to switch the animations more than once. The first animation plays when the player isn't moving and the second plays when the player does. The issue is the player will press ctrl causing the player to crouch which is good and they can move starting the second animation but when they stop they can never go back to the second animation when moving.
This is my script under ServerScriptService:
local uis = game:GetService("UserInputService")
local walking = Instance.new("BoolValue")
walking.Value = false
game.ReplicatedStorage.Crouch.Start.OnServerEvent:Connect(function(player)
if walking.Value == false then
walking.Value = true
local Animation = Instance.new("Animation", player.Character)
Animation.AnimationId = "rbxassetid://5010278985"
Animate = player.Character.Humanoid:LoadAnimation(Animation)
Animate.Priority = 1
Animate:Play()
wait()
player.Character.Humanoid.Running:Connect(function(speed)
while true do
wait()
if walking.Value == true then
wait()
Animate:Stop()
local Animation2 = Instance.new("Animation", player.Character)
Animation2.AnimationId = "rbxassetid://5062446283"
Animate2 = player.Character.Humanoid:LoadAnimation(Animation2)
Animate2.Priority = 1
Animate2:Play()
while true do
wait()
if speed <= 1 then
walking.Value = false
Animate2:Stop()
Animate:Play()
break
end
end
end
end
end)
end
end)
game.ReplicatedStorage.Crouch.End.OnServerEvent:Connect(function(player)
walking.Value = false
Animate:Stop()
Animate2:Stop()
end)
I've tried playing around with the walking value and loops but I can barely put my head around it. Basically, the second animation never plays again
