Hello. In my code, there is a math.random() which calls a random piece of music from the folder RadioMusic. Everything else works, but I’m trying to find a way to make sure that the same song isn’t chosen twice. The idea is that it checks if it is, and if it is already playing then it will repick a number. Any help?
local plr = game.Players.LocalPlayer
local musicgui = plr:WaitForChild("PlayerGui"):WaitForChild("MusicGui")
local text = musicgui:WaitForChild("TextFrame").TextLabel
local imbutton = musicgui:WaitForChild("ImageButton")
local songfolder = game.Workspace:WaitForChild("RadioMusic")
local songs = songfolder:GetChildren()
imbutton.MouseButton1Click:Connect(function()
imbutton.Interactable = false
imbutton.ImageTransparency = 0.5
local music = songs[math.random(1, #songs)]
print(music.Name)
if music.Playing == true then
-- How would I redo the number here?
else
task.wait(1)
for _, song in songs do
if song:IsA("Sound") then
song.Playing = false
end
end
music.Playing = true
end
text.Text = (music.Name)
task.wait(2)
imbutton.Interactable = true
imbutton.ImageTransparency = 0
end)