So I was bassically trying to make a song play in a certain area, and then switch back to the background music once out of said area. The sound named "SONIC" is the background music, and the song named "HALO" is the music that I want to play in a certain area. So I made an ontouch function with a brick named "MusicPlay", but then I noticed a problem with this brick. If I kept stepping on it, it would change the song, but rapidly. I only wanted the song HALO to change to SONIC but it just seems random. Like for example, if SONIC is already playing, and I step on the brick, it changes it to HALO. Here's the script for MusicPlay.(I also tried to add a debounce to this because I originally thought that was the problem).
local debounce = false
script.Parent.Touched:connect(function(hit)
if not debounce then
debounce = true
if workspace.TV.Script.HALO.IsPlaying = true then --If HALO is playing then..
workspace.TV.Script.HALO.IsPlaying = false--Make HALO not play
wait(1)
workspace.SONIC.IsPlaying = true --Make Sonic play instead of HALO
end
debounce = false
end
end)
How do I fix this?
