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

This script always repeatedly picks the same audio after it ends?

Asked by 4 years ago
local sounds = {"158485547","157026036","158526174"}
local audio = workspace:WaitForChild("Music").Sound
local song = sounds[math.random(1,#sounds)]
local playing = false

audio.SoundId = "rbxassetid://"..song
local currentsong = song
while wait(1) do
    if playing == false then
        playing = true
        audio:Play()
        audio.Ended:Wait()
        song = nil
        song = sounds[math.random(1,#sounds)]
        if song == currentsong then
            song = nil
            song = sounds[math.random(1,#sounds)]
        end
        audio.SoundId = "rbxassetid://"..song
        audio:Play()
        playing = false
    end
end

For example, if the song is the 1st argument of the table, it will stay like that forever. It doesn't pick another random sound?

0
Use tick.randomseed at line 17. JesseSong 3916 — 4y
0
Sorry, but I'm not familiar with that. AcrylixDev 119 — 4y

1 answer

Log in to vote
0
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
local sounds = {sound1, sound2, sound3, sound4, sound5} -- replace with your id's
local r = Random.new()

function pickRandomSound()
    local randomIndex = r:NextInteger(1, #sounds)
    return sounds[randomIndex]
end
0
Thanks, did some testing, messed around with it, and I'm a little bit familiar with this method. AcrylixDev 119 — 4y
Ad

Answer this question