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

How to reference object that was been randomly chosen?

Asked by 3 years ago

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.

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. greatneil80 2647 — 3y
0
No, that only picks a random song. It doesn't know which one it picked, though. KneeDeepInTheDoot 13 — 3y

1 answer

Log in to vote
-1
Answered by 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
randomSong.Ended:Connect(function()
local randomSong = musicTable[math.random(1, #musicTable)]
randomSong:Play()
end)
Ad

Answer this question