#script fix?
110 messages · Page 1 of 1 (latest)
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
@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``````
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
** You are now Level 2! **
damn
close
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
oh
you need 3 at the bottom as well
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
yh
but how do i make it play with the part
example
of what i mean
but when the song ends, it automactically plays a random song from the model
yes
are u wanting it to loop just the same song?
no
I plan to have multiple songs inside the boombox
so the script chooses a random song from the selection
and play it next
I think this should work just fine, you just need the audio object to be inside the part.
so what is happening right now is it that when the song ends it just stops playing i dont understand what the issue is
the thing is
it doesnt do the thing where you get closer, the music gets louder
let me try it again
Is the sound's parent the part?
the audio has to be inside the script
thats why the "getchildren" part
or is there a way to make it find the children from the part
?
script.parent:GetChildren()
** You are now Level 1! **
yea seems to work, just one more question. Should i keep the audios looped in properties?
it does randomly choose one now
but stops playing any more when the first song is over
Any errors?
Also the script is also a child of the part so that will cause problems
no problems
it always play a randomly picked song from the part
but doesnt really play anything after it ends
Perhaps the wait() is just weird, this is just a guess but try using task.wait(RandomSound.TimeLength)
I've personally had problems with wait() behaving in strange ways
Yeah, that's what I meant with the script getting caught up in the sounds array
so what should i do>
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
could change TimeLength to Duration
** You are now Level 1! **
** You are now Level 3! **
yippee
nah dont work
thanks for cooperating gentlemen
also wait whats the local Sounds = {}
supposed to do
do I put in names
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
** You are now Level 2! **
I added a wait(0) so it doesnt do that weird pause
Does that work?
yes
¯_(ツ)_/¯
the coding lords do
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
