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

Why isn't my sound script working to change songs for a special event?

I'm trying to make an event occur in my game that happens every 100 seconds that changes the music to another sound which is different from the normal background music.

Then the event is supposed to go for 20 seconds and then revert back to the normal background music.

Below is my script and I am bad at scripting and want to know what I did wrong.

local music = game.SoundService.Buttercup --normal song playing in background
local sound = game.SoundService.Party --event song

d = 1 --for a true statement

while d == 1 do
	wait(100) --every 100 seconds event plays
	music:Stop()
	sound:Play()
	wait(20) --event plays for 20 seconds
	sound:Stop()
	music:Play()
end

1 answer

This may fix your script. The wait is at the first line of the function, this makes it so it waits 100 seconds and then plays the audio.

local music = game.SoundService.Buttercup 
local sound = game.SoundService.Party

d = true

while d == true do
    music:Stop()
    sound:Play()
    wait(100) 
    sound:Stop()
    music:Play()
    wait(20)
end

3 comments

0

Why not just do while true do instead of == true do. Remove the entire variable

0

@Ha_rriz I think you may have misunderstood. I want to wait 100 seconds between events, but it looks like with this it would play right away and then play for 100 seconds. I put notes on the side to say what I was going for.

0

Also a sidenote is that there is already music playing the background when you spawn in and when the event happens I want the sound to go away and play the event music for 20 seconds then back to normal background music.

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