Local script working only in studio

Hello everyone i’ve been trying to implement some footsteps sound based on player’s walkspeed and it actually works, the problem is that it works only in roblox studio, when i play my game in roblox the footsteps system doesn’t work, i’ve tried to put some debugs but even with that in developer console nothing appears like the script doesn’t exist, can anyone help me please?

here is the local script i’ve used

local sounds = game:GetService('SoundService')
local runtime = game:GetService('RunService')
script:WaitForChild('FootstepSounds').Parent = sounds
local materials = sounds:WaitForChild('FootstepSounds')
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local hrp = char.HumanoidRootPart
local hum = char.Humanoid
local walking

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

function getMaterial()
	local floormat = hum.FloorMaterial
	if not floormat then floormat = 'Air' end
	local matstring = string.split(tostring(floormat), 'Enum.Material.')[2]
	local material = matstring
	return material
end

local lastmat
runtime.Heartbeat:connect(function()
	if walking then
		local material = getMaterial()
		if material ~= lastmat and lastmat ~= nil then
			materials[lastmat].Playing = false
		end
		local materialSound = materials[material]

		if material == 'WoodPlanks' or material == 'Wood' then
			if hum.WalkSpeed > 7 then
				materialSound.PlaybackSpeed = 2.2
			elseif hum.WalkSpeed == 7 then
				materialSound.PlaybackSpeed = 1.3
			elseif hum.WalkSpeed == 3 then
				materialSound.PlaybackSpeed = 0.9
			end
		else
			if hum.WalkSpeed > 7 then
				materialSound.PlaybackSpeed = 1.1
			elseif hum.WalkSpeed == 7 then
				materialSound.PlaybackSpeed = 0.78
			elseif hum.WalkSpeed == 3 then
				materialSound.PlaybackSpeed = 0.45
			end
		end

		materialSound.Playing = true
		lastmat = material
	else
		for _, sound in pairs(materials:GetChildren()) do
			sound.Playing = false
		end
	end
end)

Put the script in StarterCharacterScripts. (if you’re not already doing that).

LocalScripts only run when they’re a descendant of the player or in the player’s character model.

Also one more tip, compare materials against Enum.Material., you dont need that function to get it as a string

if part.Material == Enum.Material.Wood then
  -- the character is on wood!!
end

The local script is already inside the startercharacterscripts, i’ve changed the script as you said

local sounds = game:GetService('SoundService')
local runtime = game:GetService('RunService')
script:WaitForChild('FootstepSounds').Parent = sounds
local materials = sounds:WaitForChild('FootstepSounds')
local plr = game.Players.LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local hrp = char.HumanoidRootPart
local hum = char.Humanoid
local walking

hum.Running:Connect(function(speed)
	walking = speed > hum.WalkSpeed / 2
end)

local lastMaterial
runtime.Heartbeat:Connect(function()
	if walking then
		local currentMaterial = hum.FloorMaterial
		if currentMaterial ~= lastMaterial and lastMaterial then
			local previousSound = materials:FindFirstChild(tostring(lastMaterial))
			if previousSound then
				previousSound.Playing = false
			end
		end

		local materialSound = materials:FindFirstChild(tostring(currentMaterial))
		if materialSound then
			if currentMaterial == Enum.Material.WoodPlanks or currentMaterial == Enum.Material.Wood then
				if hum.WalkSpeed > 7 then
					materialSound.PlaybackSpeed = 2.2
				elseif hum.WalkSpeed == 7 then
					materialSound.PlaybackSpeed = 1.3
				elseif hum.WalkSpeed == 3 then
					materialSound.PlaybackSpeed = 0.9
				end
			else
				if hum.WalkSpeed > 7 then
					materialSound.PlaybackSpeed = 1.1
				elseif hum.WalkSpeed == 7 then
					materialSound.PlaybackSpeed = 0.78
				elseif hum.WalkSpeed == 3 then
					materialSound.PlaybackSpeed = 0.45
				end
			end

			materialSound.Playing = true
		end

		lastMaterial = currentMaterial
	else
		for _, sound in pairs(materials:GetChildren()) do
			sound.Playing = false
		end
	end
end)

the result is the same, i walk or run and no sound plays, i don’t understand why it doesn’t work just on normal roblox. This script works when i test it in roblox studio