Walk Animation overlaps Run Animation's footstep sounds

  1. What do you want to achieve? I’m trying to make custom footstep sounds using Animation Events

  2. What is the issue? Walk Animation overlaps when I switch to the Run Animation

  3. What solutions have you tried so far?
    I tried searching the DevForum, disabling the Walk Animation when running, most of the solutions ended up being too complicated and buggy

Heres the video (volume up to hear footsteps):

Code:

local Footstep = script:WaitForChild("Footstep")

game.Players.LocalPlayer.Character.Humanoid.AnimationPlayed:Connect(function(track)
	if track.Name == "RunAnim" or track.Name == "WalkAnim" or track.Name == "SprintAnim" or track.Name == "CrouchAnim" then
		track:GetMarkerReachedSignal("Footstep"):Connect(function()
			Footstep:Play()
		end)
	end
end)

You could implement a boolean variable to verify if the player is actively running, and then exclusively play the footstep sound from the “RunAnim” animation if the variable’s value is true.

local Footstep = script:WaitForChild("Footstep")
local isRunning = false

game.Players.LocalPlayer.Character.Humanoid.Running:Connect(function(speed)
	isRunning = speed > 0
end)

game.Players.LocalPlayer.Character.Humanoid.AnimationPlayed:Connect(function(track)
	if track.Name == "RunAnim" or track.Name == "WalkAnim" or track.Name == "SprintAnim" or track.Name == "CrouchAnim" then
		track:GetMarkerReachedSignal("Footstep"):Connect(function()
			if isRunning and track.Name == "RunAnim" then
				Footstep:Play()
			elseif not isRunning and track.Name == "WalkAnim" then
				Footstep:Play()
			end
		end)
	end
end)

Your original code was playing the sound whenever the Footstep animation event marker was reached in any of the four animations you listed. I assume this is what led to the overlapping sounds when switching between walking and running. By checking the bool we created, we an make sure we only play the footstep sound from the RunAnim when it is true, and from the WalkAnim when it is false. This should ensure that they’re played at the right times.

2 Likes

Thanks! I’ve tried to take a similar approach but it never did work (womp womp).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.