Trouble creating sound when Keyframe Marker is met

Okay, so let’s get straight into it. I’m not very good at coding, and only just started. I’ve looked at documentations and other forums to find out how to make sound when a marker is met.
I don’t want to adjust the speed of the animation, but the footsteps that is out of sync annoys me!

I’m using R6, and I am also using the default Animate script that roblox players spawn with in-game.

I’ve tried to do the script with examples, but this is as far as I could get, with it leading to an error.

local Humanoid = script.parent.Humanoid

function playFootstepSound()
	local anim = Humanoid:LoadAnimation(script.Parent.Animate.walk.WalkAnim)
	print("Sound played!")

local onStep = GetMarkerReachedSignal('foothit')


I get an error "Workspace.Ssandst0rm.footsteps:8: attempt to call a nil value in the output.

I’ve been stuck on this for a while now, so any help is very much appreciated.

I am not sure, but I think you’d have to do:


Sorry if it doesn’t work.

This might work if I re-arrange the script, since the variable for the animation is only called inside of the Function. I’ll update you if it works!

Here’s some useful websites

hmm, took a look at what you said and changed it around! The function no longer exists, but the print works and the output no longer says the Marker is me calling a nil value!

Tricky part now is that the sound only plays once, and it doesn’t even matter if im walking or not! Tricky indeed.

local Humanoid = script.parent.Humanoid
anim = Humanoid:LoadAnimation(script.Parent.Animate.walk.WalkAnim)

if anim:GetMarkerReachedSignal("foothit") then
	print("Sound played!")

I think there is a Looped property, but only for AnimationTracks. You’d have to set it to true:

animTrack.Looped = true

Edit: I thought you wanted the anim to loop, sorry

There is also a Looped property for a Sound, just set the Volume to more than 0, and you shouldn’t use Play.

sound.Looped = true
sound.Volume = --the volume

And when you want it to stop, just set Looped to false or set the Volume to 0.

    print("Sound played!")