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

Why isn't this song playing in the right area?

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?

1 answer

✓ Accepted answer

I am confused how this script even causes any sound to play.

Line 5 needs to be changed to: if workspace.TV.Script.HALO.IsPlaying == true then Otherwise lua thinks you are trying to make IsPlaying true.

Line 6 and 8 also will error. A sound's IsPlaying property is read only. Line 6 needs to be: workspace.TV.Script.HALO:Pause() or workspace.TV.Script.HALO:Stop() And line 8: workspace.SONIC:Play()

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