Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to make the sound play after place ?

Asked by
Bulvyte 388 Moderation Voter
8 years ago
Edited 8 years ago

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

Log in to vote
1
Answered by
Im_Kritz 334 Moderation Voter
8 years ago

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)

0
Wait wait, when the last song is like 5 it still goes +1 so.... how do u fix that ? Bulvyte 388 — 8y
0
if currentSong > 5 then currentSong = 1 end Pawsability 65 — 8y
Ad

Answer this question