First approach
Well first, I recommend you create a pseudo table you can use to control what random values you can access, and eliminate the already chosen ones.
Second approach
Next, I'll just be optimizing some minor details that aren't really relevant in this situation, but it certainly doesn't hurt. I'll go over most of it in commented text.
local SongHolder = script.Parent
local Songs = {}
for i = 1,#SongHolder:GetChildren() do
local v = SongHolder[i]
if v:IsA("IntValue") and v.Name == "MusicId" then
Songs[i] = v.Value
end
end
Now for the part you're looking for, the random selection loop. Here we'll use a while loop, that will continuously run a numeric for loop with different values to choose from each time. Here's an example:
local SoundPlayer
local SongHolder = script.Parent
local Songs = {}
for i = 1,#SongHolder:GetChildren() do
local v = SongHolder[i]
if v:IsA("IntValue") and v.Name == "MusicId" then
Songs[i] = v.Value
end
end
SoundPlayer = Instance.new("Sound",SongHolder)
while true do
local selection = {}
for i = 1,#Songs do
selection[i] = Songs[i]
end
for i = 1,#selection do
local rand = math.random(#selection)
SoundPlayer.SoundId = "rbxassetid://"..tostring(table.remove(selection,rand))
SoundPlayer:Play()
SoundPlayer.Ended:wait()
end
end
Summary
So basically all we're doing is creating another table that holds the same references as our initial "Songs" table, and removing the random values we choose as we go down the numeric for loop, to prevent choosing the same random value again.
Questions
Hope this helped, let me know if you have any questions.
3 comments
Please edit your question and include the code in a Code Block. It will make understanding the code easier. The Code Block button is above the text field when editing the question, next to the Bold and Italics buttons (it looks like the Lua logo).
Once the code is arranged within a Code Block, I will be able to help you, because I already have the answer, but I do not know how your script actually looks like (is it a single line? Or 4? Maybe 73? I do not know!)
there you go