My footstep sound is not working

Hello! I’ve tried making footsteps when the npc is walking. But the problem is that when the npc stops walking the footstep sound keep playing.

Here is the script:

Humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Running then
		Figure.HumanoidRootPart.Footstep:Resume()
	else
		Figure.HumanoidRootPart.Footstep:Stop()
	end
end)

I will be glad if you help me.

Try this

Humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Running then
	        Figure.HumanoidRootPart.Footstep:Play()
        else if newState == Enum.HumanoidStateType.None then
	        Figure.HumanoidRootPart.Footstep:Stop()
       end
    end
end)
1 Like

Thanks. i’ll try that out! I hope its works.

1 Like

I’m not sure, but it might be your use of Play and Stop. Have your tried using PlaybackSpeed instead? That way not only would it resume where it was but it might fix your issue.

2 Likes

Thanks for help, but still does not work. By the way the footstep sound on loop.

I didn’t tried it. but i’m going to try it now.

Is still not working. I don’t know why.

Send me your code with the PlaybackSpeed added.

1 Like
Humanoid.StateChanged:Connect(function(oldState, newState)
    if newState == Enum.HumanoidStateType.Running then
		Figure.HumanoidRootPart.Footstep:Play()
		Figure.HumanoidRootPart.Footstep.PlaybackSpeed = 1
        else if newState == Enum.HumanoidStateType.None then
			Figure.HumanoidRootPart.Footstep.PlaybackSpeed = 0
       end
    end
end)

The :Play() should be outside the humanoid state changed script. It should look something like this:

Figure.HumanoidRootPart.Footstep:Play()

Humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Running then
		Figure.HumanoidRootPart.Footstep.PlaybackSpeed = 1
	else
		Figure.HumanoidRootPart.Footstep.PlaybackSpeed = 0
	end
end)

1 Like
local character = script.Parent
local humanoid = character:WaitForChild"Humanoid"
if not humanoid.RootPart then
	humanoid:GetPropertyChangedSignal"RootPart":Wait()
end
local root = humanoid.RootPart
local sound = Instance.new"Sound"
sound.SoundId = "rbxassetid://0" --Change 0 to the audio's asset ID.
sound.Parent = root

local function onRunning(speed)
	if speed > 0 then
		if sound.IsPaused then
			sound:Resume()
		else
			sound:Play()
		end
	else
		sound:Pause()
	end
end

humanoid.Running:Connect(onRunning)

Something like this should work, server script inside StarterCharacterScripts.

1 Like

Thanks, but i don’t need to do on the player. I need to do on an npc