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

Can someone help me with this problem?

Asked by 10 years ago
function onTouched(hit)
    script.Parent.Ghost:play()
end
script.Parent.Touched:connect(onTouched)

Whenever someone will touch this, it will play the sound or will play 'Ghost'

But the problem is, the song will repeat and repeat if someone keeps jumping and stepping on the brick.

So can you guys help me with this?

4 answers

Log in to vote
1
Answered by 10 years ago
function onTouched(hit)
    local ghost = script.Parent.Ghost
    if ghost.isPlaying == false then
      script.Parent.Ghost:play()
    end
end

script.Parent.Touched:connect(onTouched)

The isplaying property lets you check if the sound is playing or not.

0
Will it play only once? SuperMushroom8 15 — 10y
0
It will be able to be played again once it has finished for the first time, but it will not play multiple times in a row without stopping first. (i.e. it has to be reactivated after it finishes) duckwit 1404 — 10y
0
yes that is correct. soaprocks2 75 — 10y
Ad
Log in to vote
0
Answered by
Sublimus 992 Moderation Voter
10 years ago

You can check if the song isPlaying == false and if it is, let it activate, but if it is playing, don't let it activate:

function onTouched(hit)
    if script.Parent.Ghost.IsPlaying == false then
        script.Parent.Ghost:play()
    end
end
script.Parent.Touched:connect(onTouched)

Log in to vote
0
Answered by 10 years ago

Is it possible to add

wait(3)

or something like that?

I really wanna make a scary horror game.

Log in to vote
-1
Answered by 10 years ago

Use debounce.

Answer this question