✓ Accepted answer
To find a random a random child, you would use the GetChildren() function.
Here is an example on you could use this:
while true do
local song = script:GetChildren()[math.random(1,4)]
if song.ClassName=="Sound" then
song:play()
end
wait(2)
end
GetChildren() returns a table of all of the children in a specific instance.
I hope this helped you with your problem!
Read More On GetChildren() here
YOU CAN ALSO USE AN ALTERNATIVE WAY!
You can use ToString() since the Name Property is a string value.
Tostring() converts numbers to string values.
To use this alternative way, you must have the sounds numbered as numbers.
while true do
local song = script:findFirstChild(tostring(math.random(1,4)))
song:play()
wait(2)
end
1 comment
thanks.