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

Can you help me with sound?

So I currently have this Sound script.

script.Parent.Sound2:Play()
wait(2)     

I have it set to an onTouch but people can spam it massively... Can you let me know how I could fix it?

1 answer

Try this, tell me the problem if there is one.

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

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.Sound2:Play() --plays sound/song
		wait(60) --waits 60 seconds (the length of a song)
		debounce = false --resets debounce to false, so it's playable after 60 seconds
		script.Parent.Sound2:Stop() --stops the song
	else --otherwise song is already playing
		print('already playing') --prints that it's already playing
	end
end)   

2 comments

0

Well, it is still just a spammable

0

What he's saying is you need to add a debounce: http://wiki.roblox.com/index.php?title=Debounce

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