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
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)
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.
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.
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.
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.