I am making it so when the player stops walking while crouching, their animation freezes, but for some reason when they start walking again, it stays frozen.
if isCrouching.Value and not crouchTrack.IsPlaying and humanoid.MoveDirection.Magnitude > 0 and not runTrack.IsPlaying then
crouchTrack:AdjustSpeed(1)
crouchTrack:Play()
elseif isCrouching.Value and crouchTrack.IsPlaying and humanoid.MoveDirection.Magnitude == 0 and not runTrack.IsPlaying then
crouchTrack:AdjustSpeed(0)
elseif not isCrouching.Value and crouchTrack.IsPlaying then
crouchTrack:Stop()
Seeing the rest of your code is probably going to be valuable here.
I don’t know when isCrouching is set back to its correct value, or if you are checking via Stepped or something. I would just check when you are setting isCrouching to the correct value.
Sorry if it’s unorganized, I am trying to simply some of the unnecessarily long areas. Just so you know, all of the BoolValues work properly.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local defaultSpeed = humanoid.WalkSpeed
local camera = game.Workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local repStorage = game:GetService("ReplicatedStorage")
local stateUpdate = repStorage.Events:FindFirstChild("StateUpdate")
--------------------------------------------------
local runAnimation = Instance.new("Animation")
runAnimation.Name = "RunAnimation"
runAnimation.AnimationId = "rbxassetid://13073579735"
local runTrack = humanoid:LoadAnimation(runAnimation)
runTrack.Priority = Enum.AnimationPriority.Movement
--------------------------------------------------
local crouchAnimation = Instance.new("Animation")
crouchAnimation.Name = "CrouchAnimation"
crouchAnimation.AnimationId = "rbxassetid://13085110450"
local crouchTrack = humanoid:LoadAnimation(crouchAnimation)
crouchTrack.Looped = true
crouchTrack.Priority = Enum.AnimationPriority.Movement
--------------------------------------------------
local runKey = Enum.KeyCode.LeftShift
local crouchKey = Enum.KeyCode.C
local sprintMultiplier = 1.65
local crouchMultiplier = 0.35
local defaultFOV = 70
local runFOV = 100
local crouchFOV = 55
local FOVDuration = 0.5
--------------------------------------------------
local values = character:WaitForChild("Values")
local speedMultiplier = values:FindFirstChild("SpeedMultiplier")
local isMoving = values:FindFirstChild("IsMoving")
local isRunning = values:FindFirstChild("IsRunning")
local isCrouching = values:FindFirstChild("IsCrouching")
--------------------------------------------------
speedMultiplier:GetPropertyChangedSignal("Value"):Connect(function()
local speedMultiplier = values.SpeedMultiplier.Value
humanoid.WalkSpeed = defaultSpeed * speedMultiplier
end)
UIS.InputBegan:Connect(function(input)
if input.KeyCode == runKey and isCrouching.Value == false then
values.SpeedMultiplier.Value = sprintMultiplier
isRunning.Value = true
elseif input.KeyCode == crouchKey and isRunning.Value == false then
values.SpeedMultiplier.Value = crouchMultiplier
isCrouching.Value = true
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == runKey and isCrouching.Value == false then
values.SpeedMultiplier.Value = 1
isRunning.Value = false
elseif input.KeyCode == crouchKey and isRunning.Value == false then
values.SpeedMultiplier.Value = 1
isCrouching.Value = false
end
end)
coroutine.wrap(function()
while wait() do
if isRunning.Value and not runTrack.IsPlaying and humanoid.MoveDirection.Magnitude > 0 and not crouchTrack.IsPlaying then
TweenService:Create(camera, TweenInfo.new(FOVDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = runFOV}):Play()
runTrack:Play()
elseif isRunning.Value and runTrack.IsPlaying and humanoid.MoveDirection.Magnitude == 0 and not crouchTrack.IsPlaying then
TweenService:Create(camera, TweenInfo.new(FOVDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = defaultFOV}):Play()
runTrack:Stop()
elseif not isRunning.Value and runTrack.IsPlaying then
TweenService:Create(camera, TweenInfo.new(FOVDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = defaultFOV}):Play()
runTrack:Stop()
end
if isCrouching.Value and not crouchTrack.IsPlaying and humanoid.MoveDirection.Magnitude > 0 and not runTrack.IsPlaying then
crouchTrack:AdjustSpeed(1)
crouchTrack:Play()
elseif isCrouching.Value and crouchTrack.IsPlaying and humanoid.MoveDirection.Magnitude == 0 and not runTrack.IsPlaying then
crouchTrack:AdjustSpeed(0)
elseif not isCrouching.Value and crouchTrack.IsPlaying then
crouchTrack:Stop()
end
end
end)()
coroutine.wrap(function()
while wait() do
if humanoid.MoveDirection.Magnitude > 0 then
isMoving.Value = true
elseif humanoid.MoveDirection.Magnitude == 0 then
isMoving.Value = false
end
end
end)()
Print out each individual property involved.
This is isCrouching, crouchTrack.IsPlaying, and the humanoid.MoveDirection.Magntitude.
See if they match your expected behavior.