Sound won't play when the player touches the parts

I’m making a script that plays a sound every time the player touches the parts, but it doesn’t seem to work. I’ve rewritten the script in a few different ways but I still can get it to work. Any help would be highly appreciated.

  1. What do you want to achieve?
    I want the sound to play every time the player touches the parts

  2. What is the issue?
    Sound isn’t playing

local sound = game:GetService("ReplicatedStorage"):WaitForChild("Sounds"):WaitForChild("DirtStep")

for i,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("Part") and v.Name == "Part" then
		v.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Humanoid") then
				sound:Play()
			end
		end)
		
		v.TouchEnded:Connect(function(hit)
			sound:Pause()
		end)
	end
end

Explorepath

Maybe consider doing this. Might not work but maybe try.

  local sound = game:GetService("ReplicatedStorage"):WaitForChild("Sounds").DirtStep
    script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    sound:Play()
    end
    end)
    script.Parent.TouchEnded:Connect(function()
    sound:Pause()
    end)

Your script is perfectly fine, its just that the script cannot reach the sound or the sound cannot be played in the parent it is in. I suggest putting the sound inside workspace or the player.

2 Likes

I think you should put the sound inside the part just like what @GoodPuppyPaw3 said.

1 Like