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

How to make the sound play after place ?

Example 1 played, 2 plays and goes on chronologically..

local Songs = {1, 2, 3, 4, 5} -- just an example lol
local Play = true
local ID = 000000

function New()
	ID = nil
	ID = Songs[math.random(1,#Songs)] -- i don't want dis :I(
end

game:GetService("RunService").Heartbeat:connect(function()
	if Play == true then
		New()
		Play = false
		script.Parent.Parent.Background:Pause()
		script.Parent.Parent.Background.SoundId="rbxassetid://"..ID
		wait()
		script.Parent.Parent.Background:Play()
		wait(script.Parent.Parent.Background.TimeLength)
		script.Parent.Parent.Background:Pause()
		Play = true
	end
end)

1 answer

✓ Accepted answer

Have a current song variable in your code to keep track of your songs.

local currentSong = 1

Then have the variable jump up every time you switch songs.

currentSong = currentSong + 1

Complete code

local Songs = {1, 2, 3, 4, 5} -- just an example lol
local Play = true
local ID = 000000
local currentSong = 1

function New()
    ID = nil
    ID = Songs[currentSong] -- i don't want dis :I(
	currentSong = currentSong + 1
end

game:GetService("RunService").Heartbeat:connect(function()
    if Play == true then
        New()
        Play = false
        script.Parent.Parent.Background:Pause()
        script.Parent.Parent.Background.SoundId="rbxassetid://"..ID
        wait()
        script.Parent.Parent.Background:Play()
        wait(script.Parent.Parent.Background.TimeLength)
        script.Parent.Parent.Background:Pause()
        Play = true
    end
end)

2 comments

0

Wait wait, when the last song is like 5 it still goes +1 so.... how do u fix that ?

0

if currentSong > 5 then currentSong = 1 end

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