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

Trying to make a sound trigger script. Help?

This is what I've got so far.

function onTouched(hit)
script.Parent.Sound:play()
if script.Parent.TouchEnded then
script.Parent.Sound.IsPlaying=false
end
end

script.Parent.touched:connect(onTouched)

When the brick is touched, the sound will play. But when the brick is not being touched anymore, the sound stops. When the brick is touched again, the sound plays again. So if the brick was as big as the place where the music would play, it could provide background music. For example, if the brick was the same size as a supermarket, it would play when the player steps into it and would cease when the player steps out of it.

3 comments

0

What? Also, don't use this method for providing music for a specific area. Making a huge brick like that with the touched event would be laggy and glitchy.

0

@wfv014 is there any other way I could accomplish this then?

0

You'd need to do something such as Region3, not really sure how it would work exactly, but that's what I'd try.

1 answer

If you're trying to make it trigger different sounds on different areas, just have a block that triggers the noise once they enter the area, and have a block that ends the noise after they leave that are. You could use that current script you have, but modify it to trigger only and have the same script in another block but have it end when its touched.

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