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

How to reference object that was been randomly chosen?

I have code that randomizes songs, and I found a solution, but I need help coding it. (Keep scrolling low-resolution users for explanation)

local musicTable =  script.Music:GetChildren() --  yes i recycled this from my impact sound script :troll:
local randomSong = musicTable[math.random(1, #musicTable)]

What I want to do here is I want to reference the randomized song so I can write some code on when it ends and I can trigger a new sound to be picked.

2 comments

0

Fun fact: You referenced the song. randomSong is the referenced object, displayed as a variable. I'm not sure what you are asking other than this.

0

No, that only picks a random song. It doesn't know which one it picked, though.

1 answer

randomSong.Ended:Connect(function()
local randomSong = musicTable[math.random(1, #musicTable)]
randomSong:Play()
end)

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