#script fix?

110 messages · Page 1 of 1 (latest)

sand topaz
#

I am trying to make a boombox that plays music, but everytime the music ends, it randomly choose a audio file from the model and plays it next

#

let me paste script

#

wait(1)
while true do
local Sounds = script:GetChildren()
local RandomIndex = math.random(1,#Sounds)
local RandomSound = Sounds[RandomIndex]
RandomSound:Play()
wait(RandomSound.TimeLength)
end

#

i wanna make it

#

so like it can be played in a prop

#

like with promixity audio

rugged locust
#

@sand topaz

sand topaz
rugged locust
#

put it in ``````

#

lua

#

like that

sand topaz
#
while true do
    local Sounds = script:GetChildren()
    local RandomIndex = math.random(1,#Sounds)
    local RandomSound = Sounds[RandomIndex]
    RandomSound:Play()
    wait(RandomSound.TimeLength)
end``````
rugged locust
#

like

#

but lua

#

is in the#

#

/like

#

hm

sand topaz
#
wait(1)
while true do
    local Sounds = script:GetChildren()
    local RandomIndex = math.random(1,#Sounds)
    local RandomSound = Sounds[RandomIndex]
    RandomSound:Play()
    wait(RandomSound.TimeLength)
end
dusty driftBOT
#

studio** You are now Level 2! **studio

sand topaz
#

damn

rugged locust
#

close

sand topaz
#

ok

#
a ```
#

i suck at this

rugged locust
#

close

fervent dove
#
wait(1)
while true do
    local Sounds = script:GetChildren()
    local RandomIndex = math.random(1,#Sounds)
    local RandomSound = Sounds[RandomIndex]
    RandomSound:Play()
    wait(RandomSound.TimeLength)
end
#

there

bright nest
sand topaz
#

oh

fervent dove
#

you need 3 at the bottom as well

sand topaz
#
wait(1)
while true do
    local Sounds = script:GetChildren()
    local RandomIndex = math.random(1,#Sounds)
    local RandomSound = Sounds[RandomIndex]
    RandomSound:Play()
    wait(RandomSound.TimeLength)
end
#

something like this

fervent dove
#

yh

sand topaz
#

but how do i make it play with the part

sand topaz
#

of what i mean

#

but when the song ends, it automactically plays a random song from the model

rugged locust
#

yes

fervent dove
#

are u wanting it to loop just the same song?

sand topaz
#

I plan to have multiple songs inside the boombox

#

so the script chooses a random song from the selection

#

and play it next

bright nest
fervent dove
#

so what is happening right now is it that when the song ends it just stops playing i dont understand what the issue is

sand topaz
#

it doesnt do the thing where you get closer, the music gets louder

#

let me try it again

bright nest
#

Is the sound's parent the part?

sand topaz
sand topaz
#

thats why the "getchildren" part

#

or is there a way to make it find the children from the part

#

?

bright nest
dusty driftBOT
#

studio** You are now Level 1! **studio

sand topaz
#

huh

#

never actually thought of that

sand topaz
#

it does randomly choose one now

#

but stops playing any more when the first song is over

bright nest
#

Also the script is also a child of the part so that will cause problems

sand topaz
#

it always play a randomly picked song from the part

#

but doesnt really play anything after it ends

bright nest
#

I've personally had problems with wait() behaving in strange ways

sand topaz
bright nest
# sand topaz

Yeah, that's what I meant with the script getting caught up in the sounds array

bright nest
#

Keep ```lua

RandomSound:Play()```

#

I haven't tried it but try this

local Sounds = {}

for i, child in ipairs(script.Parent:GetChildren())  do
    if child:IsA("Sound") then
        Sounds[i] = child
    end
end

while true do
    
    local RandomIndex = math.random(1,#Sounds)
    local RandomSound = Sounds[RandomIndex]
    RandomSound:Play()
    task.wait(RandomSound.TimeLength)
end
#

It should get all the children of the parent and only put the sounds in Sounds

fervent dove
#

could change TimeLength to Duration

dusty driftBOT
#

studio** You are now Level 1! **studio

sand topaz
dusty driftBOT
#

studio** You are now Level 3! **studio

sand topaz
#

glad it works

bright nest
#

yippee

sand topaz
#

theres some 1 second pauses sometimes

#

but its alright

sand topaz
#

thanks for cooperating gentlemen

sand topaz
#

supposed to do

#

do I put in names

bright nest
#

It creates an array where we append to in the for loop

#

Atleast that's what it is supposed to do

#

Idk if it works tbh

dusty driftBOT
#

studio** You are now Level 2! **studio

sand topaz
#

I added a wait(0) so it doesnt do that weird pause

bright nest
#

Does that work?

sand topaz
#

yes

bright nest
#

???

#

I swear, wait() is the most cursed thing of all

sand topaz
#

if it works it works

#

I dont make the rules

bright nest
#

¯_(ツ)_/¯

sand topaz
#

the coding lords do

true pilot
#

If you’re still have problems it could because of the random index value for each instead set +1 index after each song goes then have it play the song at that index so it goes in order and when it goes to the largest index (last song) set index to zero or whatever first index is in lua