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)
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)
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.
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)
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.