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 11 years ago
1function onTouched(hit)
2    script.Parent.Ghost:play()
3end
4script.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 11 years ago
1function onTouched(hit)
2    local ghost = script.Parent.Ghost
3    if ghost.isPlaying == false then
4      script.Parent.Ghost:play()
5    end
6end
7 
8script.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 — 11y
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 — 11y
0
yes that is correct. soaprocks2 75 — 11y
Ad
Log in to vote
0
Answered by
Sublimus 992 Moderation Voter
11 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:

1function onTouched(hit)
2    if script.Parent.Ghost.IsPlaying == false then
3        script.Parent.Ghost:play()
4    end
5end
6script.Parent.Touched:connect(onTouched)
Log in to vote
0
Answered by 11 years ago

Is it possible to add

1wait(3)

or something like that?

I really wanna make a scary horror game.

Log in to vote
-1
Answered by 11 years ago

Use debounce.

Answer this question