How do I make sound play when a part is touched by a person and not NPC. I have walking npcs walking around and they keep messing up the sound. How would I make it so the sound would only play when a real player touches the part?
local sound = Instance.new("Sound", Workspace) sound.Pitch = 1 sound.SoundId = "rbxassetid://902587196" sound.Volume = 1 sound.Looped = false local playonce = false script.Parent.Touched:Connect(function() if not playonce then playonce = true sound:play() end end)
You could make the NPC's health to 101, and then do this:
local sound = Instance.new("Sound", Workspace) sound.Pitch = 1 sound.SoundId = "rbxassetid://902587196" sound.Volume = 1 sound.Looped = false local playonce = false script.Parent.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if humanoid then if humanoid.Health == 100 then if playonce == false then playonce = true sound:Play() end end end end)