Help with custom Foosteps

So I decided to make a custom footstep sounds system using uglyburger0 footstep module, but I’ve encountered a problem, whenever I only hear the footstep sound only once

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

--|| Modules ||--
local FootstepModule = require(game.ReplicatedStorage.Modules.Utility.FootstepModule)

--|| Variables ||--
local Player = Players.LocalPlayer
local Character = Player.Character
if not Character or not Character.Parent then
	Character = Player.CharacterAdded:Wait()
end

local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")

local CreateFootstepSound = (function(SoundId)
	local FootstepSound = Instance.new("Sound")
	FootstepSound.SoundId = SoundId
	FootstepSound.Parent = Character:WaitForChild("HumanoidRootPart")
	
	FootstepSound:Play()
	FootstepSound.Stopped:Wait()
	FootstepSound:Destroy()
end)

local RandomFootstepSound = (function()
	local MaterialTable = FootstepModule:GetTableFromMaterial(Humanoid.FloorMaterial)
	
	if MaterialTable then
		local RandomFootstepSound = FootstepModule:GetRandomSound(MaterialTable)
		CreateFootstepSound(RandomFootstepSound)
	end
end)

coroutine.wrap(function()
	local Animate = Character:WaitForChild("Animate")
	local WalkAnimation = Animate.walk.WalkAnim
	local WalkAnimTrack = Animator:LoadAnimation(WalkAnimation)
	
	if WalkAnimTrack:GetMarkerReachedSignal("Footstep") then
		RandomFootstepSound()
	end
end)()

Thanks in advance!

Your function is merely looking for the marker once and hence such it will only play the sound once I recommend setting a connection to the marker signal

WalkAnimTrack:GetMarkerReachedSignal("Footstep"):Connect(RandomFootStepSound)

This will run the RandomFootStepSound everytime that marker is reached.

So man sup, thanks for the response, but could u help me with another thing, i asked one of my friends to help me “enhance” my script and i also used ur recommendation in the script

--|| Services ||--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

--|| Modules ||--
local FootstepModule = require(game.ReplicatedStorage.Modules.Utility.FootstepModule)

--|| Variables ||--
local Player = Players.LocalPlayer
local Character = Player.Character
if not Character or not Character.Parent then
	Character = Player.CharacterAdded:Wait()
end

local Humanoid = Character:WaitForChild("Humanoid")
local RootPart = Character:WaitForChild("HumanoidRootPart")
local Animator = Humanoid:WaitForChild("Animator")

local AnimationPlayed = Animator.AnimationPlayed

--|| Functions ||--
local function CreateFootstepSound(SoundId)
	local Sound = Instance.new("Sound")
	Sound.Name = "FootstepSound"
	Sound.RollOffMaxDistance = 50
	Sound.Volume = 0.45
	Sound.SoundId = SoundId
	Sound.Parent = RootPart
	
	Sound:Play()
	Sound.Ended:Connect(function()
		Sound:Destroy()
	end)
end

local function RandomFootstepSound()
	local MaterialTable = FootstepModule:GetTableFromMaterial(Humanoid.FloorMaterial)

	if MaterialTable then
		local RandomFootstepSound = FootstepModule:GetRandomSound(MaterialTable)
		CreateFootstepSound(RandomFootstepSound)
	end
end

AnimationPlayed(function(AnimationTrack)
	if not AnimationTrack.Animation then
		return
	end

	local AnimationId = AnimationTrack.Animation.AnimationId:match("[/=](%d+)")

	if not AnimationId then
		return
	end

	if AnimationId == "12556152822" or AnimationId == "12556156905" then
		AnimationTrack:GetMarkerReachedSignal("Footstep"):Connect(RandomFootstepSound)
	end
end)

But for some reason i get this error

Workspace.SussyZets.StarterScripts.Footstep:46: attempt to call a RBXScriptSignal value

Also sorry if am being too annoying

Could you take a screenshot of your code where it threw that error?

It appears on line 46 you did AnimationPlayed(function(AnimationTrack) this is mostly correct besides the fact that you forgot to add :Connect() to it. So it would look something like this AnimationPlayed:Connect(function(AnimationTrack)

Yo thank you, that worked again, can’t believe that it was such a simple thing, but now i have another problem, you see when walked it’s all normal and working, but everytime i sprint it just overlaps the animation events, so am guessing should i make so whenever i press the sprint key i make the walk animation stop, or if there is another better way of doing it??

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