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 6 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:

01local Sound = script.Parent.Sound
02local Set = false
03 
04function onTouched(hit)
05    if Set == false then
06        Sound:Play()
07    elseif Set == true then
08        Sound:Stop()
09    wait(3)
10    Sound:Stop()
11    Set = true

Help is Greatly appreciated.

1 answer

Log in to vote
0
Answered by 6 years ago

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

01local Sound = script.Parent.Sound
02local Set = false
03 
04script.Parent.Touched:Connect(function(part)
05   if not Set then
06      Set = true
07      Sound:Play()
08      wait(3)
09      Sound:Stop()
10      Set = false
11   else
12      Sound:Stop()
13      Set = false
14   end
15end)
1
-1 for not explaining your solution. User#24403 69 — 6y
Ad

Answer this question