Footsteps sounds for game [HELP]

Hi! I’ve been working on a game rn, I need to play footsteps sounds.
The problem is that my code is not actually working as expected here it is

function initPlayerSteppingSounds()
	
	-- Footstep sounds
	local LeftLegDetector = Instance.new("Part") -- Create a part for detecting the floor
	local RightLegDetector = Instance.new("Part")
	local CharLeftLeg : Part = Char["Left Leg"]
	local CharRightLeg : Part = Char["Right Leg"]
	LeftLegDetector.Parent = _SERVICES.Workspace
	RightLegDetector.Parent = _SERVICES.Workspace
	
	LeftLegDetector.Anchored = true
	RightLegDetector.Anchored = true
	
	LeftLegDetector.Size = Vector3.new(0.12, 0.04, 0.12)
	RightLegDetector.Size = Vector3.new(0.12, 0.04, 0.12)
	
	LeftLegDetector.Color = Color3.fromRGB(240,25,240)
	RightLegDetector.Color = Color3.fromRGB(240,25,240)
	
	_SERVICES.RunService.RenderStepped:Connect(function(dt)
		LeftLegDetector.Position = Vector3.new(CharLeftLeg.Position.X, CharLeftLeg.Position.Y - 1.2, CharLeftLeg.Position.Z)
		RightLegDetector.Position = Vector3.new(CharRightLeg.Position.X, CharRightLeg.Position.Y - 1.2, CharRightLeg.Position.Z) 
	end)
	
	local SelectedSoundId
	
	Hum.Running:Connect(function()
		LeftLegDetector.Touched:Connect(function(basePart)
			if basePart ~= CharLeftLeg then
				print("Touched something")
				if Hum.FloorMaterial == PlrStepsSounds[Hum.FloorMaterial] then

				end
			else
				print("Touched Leg") -- testing
			end
		end)
	end)
end

Btw don’t run this
If anyone could help, or tell me what to do it would be helpful, thanks!
Tell me if you need more details about it

Why not just use :GetPropertyChangedSignal for this?

function initPlayerSteppingSounds()
	Hum:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
		if Hum.FloorMaterial == PlrStepsSounds[Hum.FloorMaterial] then
			-- Your code here
		end
	end)
end

I did this:

function initPlayerSteppingSounds()
	local running = false
	local sound = Instance.new("Sound")
	local selectedMaterial
	local Material
	
	sound.Parent = Char.Head
		
	Hum:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
		Hum.Running:Connect(function(speed)
			Material = Hum.FloorMaterial.Name

			if PlrStepsSounds[Material] ~= nil and speed > 0 then
				selectedMaterial = PlrStepsSounds[Material]
				if #selectedMaterial > 0 then
					sound.SoundId = selectedMaterial[math.random(1, #selectedMaterial)]
					sound.Playing = true
				end
			else
				sound:Stop()
			end
		end)
	end)
end

But I don’t really know how to repeat the steps.
And I tried using a while loop like this:

while true do
	sound.SoundId = selectedMaterial[math.random(1, #selectedMaterial)]
	sound.Playing = true
	task.wait(sound.TimeLength)
end

Didn’t work pretty well