Custom player soudnds script not working (RbxCharacterSounds)

I am trying to make custome walk sounds for diffrent materials in roblox but it won’t work. The value seemes to be changing but it never gets to the walking sound. Am I suppose to use somthing other than while true do? if yall have a diffrent methood of doing this yall can tell me that aswell. Thank you all for your time! ask questions if you need!

local plrs =  game:GetService("Players").LocalPlayer
local char =  plrs.Character or plrs.CharacterAdded:Wait() 
local Humanoid = char:FindFirstChild("Humanoid") or char:WaitForChild("Humanoid")
local walkset = ""

while true do
	print(walkset)
	wait()
	if Humanoid then
		if Humanoid.FloorMaterial == Enum.Material.Grass or Humanoid.FloorMaterial == Enum.Material.LeafyGrass then
			walkset = "rbxassetid://notdisplayedforcopyingreasons"
		end
		if
			Humanoid.FloorMaterial == Enum.Material.Concrete or Humanoid.FloorMaterial == Enum.Material.Slate or
				Humanoid.FloorMaterial == Enum.Material.Pavement
		then
			walkset = "rbxassetid://notdisplayedforcopyingreasons" 
		end
	end
end

-- Roblox character sound script

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local SOUND_DATA : { [string]: {[string]: any}} = {
	Climbing = {
		SoundId = "rbxasset://sounds/action_footsteps_plastic.mp3",
		Looped = true,
	},
	Died = {
		SoundId = "rbxasset://sounds/uuhhh.mp3",
	},
	FreeFalling = {
		SoundId = "rbxasset://sounds/action_falling.mp3",
		Looped = true,
	},
	GettingUp = {
		SoundId = "rbxasset://sounds/action_get_up.mp3",
	},
	Jumping = {
		SoundId = "rbxasset://sounds/action_jump.mp3",
	},
	Landing = {
		SoundId = "rbxasset://sounds/action_jump_land.mp3",
	},
	Running = {
		SoundId = walkset,
		Looped = true,
		Pitch = 1.2,
	},
	Splash = {
		SoundId = "rbxasset://sounds/impact_water.mp3",
	},
	Swimming = {
		SoundId = "rbxasset://sounds/action_swim.mp3",
		Looped = true,
		Pitch = 1.6,
	},
}

1 Like

NOTE; it might be awhile till i see the replies

1 Like

Try to use :GetPropertyChangedSignal() I mean like this:

Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	if Humanoid.FloorMaterial == Enum.Material.Grass or Humanoid.FloorMaterial == Enum.Material.LeafyGrass then
		walkset = "rbxassetid://notdisplayedforcopyingreasons"
	elseif Humanoid.FloorMaterial == Enum.Material.Concrete or Humanoid.FloorMaterial == Enum.Material.Slate or Humanoid.FloorMaterial == Enum.Material.Pavement then
		walkset = "rbxassetid://notdisplayedforcopyingreasons"
	end
end)

It should work better than while true do

Okay i will try this out! thank you!

1 Like