Why wont a mesh play a sound when touched

I’ve been working on a game, quiet like other games when you pick or touch an item I tried to make the sound play but didnt work.

Here is my code

local sound = script.Parent.Sound

script.Parent.Touched:Connect(function(touched)
	local humanoid = touched.Parent:WaitForChild("Humanoid")
	if humanoid then
		if not sound.IsPlaying then
			sound:Play()
		end
	end
end)

I tried putting the code in and out of the sound but will not work, here is the soundID
: rbxassetid://1169755927

Any help will be very much appreciated.

4 Likes

Try this, it may fix your issue.

local sound = script.Parent.Sound
local Players = game:GetService("Players")


script.Parent.Touched:Connect(function(touched)
	local humanoid
	local Character = touched:FindFirstAncestorOfClass("Model")
	if Players:GetPlayerFromCharacter(Character) then
		humanoid = Character:FindFirstChildOfClass("Humanoid")
	end
	if humanoid then
		if not sound.IsPlaying then
			sound:Play()
		end
	end
end)
5 Likes

Thank you for responding, I’ve tried your code and it still doesn’t play the sound.

2 Likes

How long is the sound? is it even worth checking if it’s playing?

1 Like

Hello! Have you verified that all the mesh’s properties are correct? Is the script a local one or server one?

2 Likes

Have you tried print debugging? Print debugging is basically just putting print statements on each line of code and wherever it doesn’t print is the issue.

3 Likes

I just used the exact same script as yours with the same ID and it worked. Not sure what the issue is, maybe its a bug. Try restarting studio or ensure the sound is in the part.

2 Likes

Firstly—is it a mesh part or a part with a file mesh in it? If it’s a part with a file mesh, cut the meshID out of it, scale it as you’d like as a part, then paste the meshID back in and use the scale properties to configure it’s visual size.

If it’s a mesh part turn on CanTouch if it’s off

1 Like

Why are you using WaitForChild when the Humanoid is already loaded in, this is the wrong use of WaitForChild

1 Like

I just checked the sound is like 1.8 seconds…

1 Like

The situation might be as simple as having CanTouch turned off on the MeshPart itself. If you’re using the SpecialMesh class, those don’t have collisions and use the BaseParts collision box instead, so make sure it’s sized up correctly.

If you’re using a MeshPart, ensure CollisionFidelity it set correctly, and that the CollisionGroup is also set to Default. In most cases, having these configured incorrectly can nullify Touch events.

Double check:

  • That CanTouch is ON
  • CollisionGroup is set to Default.
  • …and that CollisionFidelity is set to Default or whatever mode best represents the shape of your Mesh. For more complex meshes, PreciseConvexDecomposition is a good start.
1 Like

Properties on the mesh part hs berely been touch everything is on including:

  • Cantouch
  • everything is set to Defualt

Yeah, I don’t know if it’s just an issue with mine, but nothing seems to work.

Um this is a server script right?

Does the audio play from the properties window? Perhaps the volume is too low?

If you do different kinds of tests then we can identify where the problem lies