Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to make a sound play only once when Touched???

Asked by 5 years ago

This is really confusing as I only need it to play Once, but whenever I collide, it replays the sound.

Here's What I have so far:

local Sound = script.Parent.Sound
local Set = false

function onTouched(hit)
    if Set == false then
        Sound:Play()
    elseif Set == true then
        Sound:Stop()
    wait(3)
    Sound:Stop()
    Set = true

Help is Greatly appreciated.

1 answer

Log in to vote
0
Answered by 5 years ago

This assumes you have a part in workspace with this script inside it:

local Sound = script.Parent.Sound
local Set = false

script.Parent.Touched:Connect(function(part)
   if not Set then
      Set = true
      Sound:Play()
      wait(3)
      Sound:Stop()
      Set = false
   else
      Sound:Stop()
      Set = false
   end
end)
1
-1 for not explaining your solution. User#24403 69 — 5y
Ad

Answer this question