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

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

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?

3 comments

0

Use tick.randomseed at line 17.

0

Sorry, but I'm not familiar with that.

1 answer

✓ Accepted answer
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

1 comment

0

Thanks, did some testing, messed around with it, and I'm a little bit familiar with this method.

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