Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Can someone help me with this problem?

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

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.

3 comments

0

Will it play only once?

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)

0

yes that is correct.

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)

Is it possible to add

wait(3)

or something like that?

I really wanna make a scary horror game.

This discussion is preserved as it was. New answers, comments, and votes are closed.