What is more efficient then a while loop for Player floor material sound script?

I’m trying to optimize my game and find more efficient ways of executing certain events. I have a while loop that’s looping through what floor material the player is on and then changing the SoundId’s for that specific floor material the player is running on.
Any better idea’s?

local player = game.Players.LocalPlayer

local soundtable = {
	["Grass"] = "rbxassetid://4085862552";
	["Concrete"] = "rbxassetid://4085860959";
	["Plastic"] = "rbxassetid://4518544160";
	["SmoothPlastic"] = "rbxassetid://4518544160";
	["Fabric"] = "rbxassetid://133705377";
	["Glass"] = "rbxassetid://4085889170";
	["Neon"] = "rbxassetid://3444211679";
	["Metal"] = "rbxassetid://5122562358";
	["Air"] = "";
	["Wood"] = "rbxassetid://2812419402";
	["WoodPlanks"] = "rbxassetid://4085869581";
	["Slate"] = "rbxassetid://4516570901";
	["CorrodedMetal"] = "rbxassetid://4085894561";
	["DiamondPlate"] = "rbxassetid://3477114901";
	["Foil"] = "rbxassetid://2647292698";
	["Ice"] = "rbxassetid://138214900";
	["Brick"] = "rbxassetid://156659098";
	["Sand"] = "4085868134";
	["Granite"] = "rbxassetid://3444211679";
	["Marble"] = "rbxassetid://3444211679";
	["Pebble"] = "rbxassetid://131172500";
	["Cobblestone"] = "rbxassetid://3444211679";
	["ForceField"] = "rbxassetid://685857471"
}

delay(0, function()
	while wait() do
		local char = player.Character
		local sound = player.Character.HumanoidRootPart.Running
		sound.SoundId = soundtable[char.Humanoid.FloorMaterial.Name]
		sound.Volume = .2
		sound.PlaybackSpeed = math.random(10,12)/10
	end
end)
1 Like
Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
    -- Basically do the same thing u did before here
end);
2 Likes