--script:WaitForChild('FootstepSounds').Parent = sounds

local materials = script.Parent:WaitForChild('FootstepSounds')
local plr = script.Parent
repeat wait() until plr
local char = plr
local hum = char.Humanoid
local hrp = hum.RootPart
local walking

hum.Running:connect(function(speed)
	if speed > hum.WalkSpeed/2 then
		walking = true
	else
		walking = false
	end
end)

function getMaterial()
	
	local material = script.Parent.Head.Footstep
end

local lastmat
local debounce = false
runtime.Heartbeat:connect(function()
	if walking and debounce == false then
		local material = getMaterial()
		if material ~= lastmat and lastmat ~= nil then
			materials[lastmat].Playing = false
		end
		local materialSound = materials[material]:Clone()
		materialSound.Playing = true
		lastmat = material
		debounce = true
		wait(1.5)
		debounce = false
		materialSound:Destroy()
	else
		for _,sound in pairs(materials:GetChildren()) do
			sound.Playing = false
		end
	end
end)
