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

Can you help me with onTouched events?

Asked by 8 years ago

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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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)   
0
It doesnt even play the sound at all, when i touch the brick TixyScripter 115 — 8y
0
Are there any errors? Goulstem 8144 — 8y
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? TixyScripter 115 — 8y
0
Like in the last question you helped me on? TixyScripter 115 — 8y
View all comments (2 more)
0
Yeah.. do pretty much exactly what I helped you with in the last question Goulstem 8144 — 8y
0
Thanks for helping me on this stuff, your the only one who ever helps meh. :D TixyScripter 115 — 8y
Ad

Answer this question