I'm having issues getting this script to work

I am trying to use KeyframeReached to fire a sound based on what material you are walking on. (Material-based footsteps)
The sound table I’m using is uglyburger0’s FootstepModule

My issue is I cannot seem to get KeyframeReached to do anything, and if I do, I just get an error. I’ve tried using GetMarkerReachedSignal, but that does not work either.

I have looked all over the forum for a solution, but I can’t find any that matches my problem.

local character = workspace:WaitForChild(game.Players.LocalPlayer.Name)
local footsteps = require(game.ReplicatedStorage.FootstepModule)
local humanoid = character.Humanoid

local function CreateSound(soundId)
	local sound = Instance.new("Sound")
	sound.SoundId = soundId
	sound.Parent = workspace

	sound:Play()
	sound.Ended:Wait()
	sound:Destroy()
end

local Animation = character.Animate.walk.WalkAnim
local AnimationTrack = humanoid:LoadAnimation(Animation)
AnimationTrack.KeyframeReached():Connect(function(name)
	if name == "Footstep" then 
		print("Footstep")
		local MaterialTable = footsteps:GetTableFromMaterial(humanoid.FloorMaterial)
		if MaterialTable then
			print("MaterialTable")
			local RandomSound = footsteps:GetRandomSound(MaterialTable)
			CreateSound(RandomSound)
		end
	end
end)

Shouldn’t it be Animation.KeyframeReached:Connect(function(name)

image

Actually, you need to do AnimationTrack.KeyframeReached:Connect(function(name). Sorry.

1 Like