Play 1 Sound when Touched

  1. What do you want to achieve?
    I want to my script play only 1 SOUND when touched.

  2. This is my script
    Also, the issue is that when i touch, it plays every sound, and i want to play only 1.

ids = {9118147709,6932519682,3571339763,8948378982}

local instance = script.Parent

instance.Touched:Connect(function(Obj)
local h = Obj.Parent:FindFirstChild(“Humanoid”)
if h then
h.Health = 0
local sound = Instance.new(“Sound”,h.Torso)
local i = (ids[math.random(1,#ids)])
sound.SoundId = “http://www.roblox.com/asset/?id=” … i
sound.MaxDistance = 100
sound.Volume = 2
sound:play()
wait(8)
sound:stop()
sound:remove()
end
end)
´´´
3. I already tried to put an wait() but still din’t work.

Is the issue that multiple sounds play at once? Or is it no sounds play at all?

It plays multiple sounds when touched

Try this;

ids = {9118147709,6932519682,3571339763,8948378982}

local instance = script.Parent
local playing = false

instance.Touched:Connect(function(Obj)
local h = Obj.Parent:FindFirstChild(“Humanoid”)
   if h and playing == false then
    playing = true
    h.Health = 0
    local sound = Instance.new(“Sound”,h.Torso)
    local i = (ids[math.random(1,#ids)])
   sound.SoundId = “http://www.roblox.com/asset/?id=” … i
   sound.MaxDistance = 100
  sound.Volume = 2
  sound:Play()
  task.wait(8)
  playing = false
  sound:Stop()
  sound:Remove()
end
end)
1 Like

yeah that I’ll delete mine 303