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

Can you help me with onTouched events?

Hello, TixyScripter here with another question dealing with Sound.... I currently have this script that has a Debounce so that people cannot spam the sound when they touch the brick.

debounce = false --use a debounce to check if it's playing already or not

function onTouched(hit)
script.Parent.Touched:connect(function(hit) --touched event
    if debounce == false then --after it's touched, if debounce is false then
        debounce = true --changes debounce to true
        script.Parent.Sound:Play() --plays sound/song
        wait(1) --waits 60 seconds (the length of a song)
        debounce = false --resets debounce to false, so it's playable after 60 seconds
        script.Parent.Sound:Stop() --stops the song
    else --otherwise song is already playing
        print('already playing') --prints that it's already playing
    end
end)   
script.Parent.Touched:connect(onTouched)

When I touch the brick the sound doesn't play at all and I don't know why, please halp!

1 answer

✓ Accepted answer

Why do you have two functions inside of eachother? Just remove the first one and you should be good.

debounce = false

script.Parent.Touched:connect(function(hit)
	if debounce == false then
		debounce = true
		script.Parent.Sound:Play()
		wait(1)
		debounce = false
		script.Parent.Sound:Stop()
	else
		print('already playing')
	end
end)   

6 comments

0

It doesnt even play the sound at all, when i touch the brick

0

Are there any errors?

0

Nothing, I just did something wrong, is there anyway this could be made compatiable with the PlayerGui thing so that only the Tycoon owner heres it?

0

Like in the last question you helped me on?

0

Yeah.. do pretty much exactly what I helped you with in the last question

0

Thanks for helping me on this stuff, your the only one who ever helps meh. :D

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