generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Play random sound from list

Previous Thread :: Next Thread 
xX420mlgnoscopeXx is not online. xX420mlgnoscopeXx
Joined: 28 Nov 2015
Total Posts: 73
15 May 2015 10:16 AM
Say I have 4 sounds. How do I make a script play a random one and play a different one when it ends?
Report Abuse
xX420mlgnoscopeXx is not online. xX420mlgnoscopeXx
Joined: 28 Nov 2015
Total Posts: 73
15 May 2015 11:01 AM
bump help
Report Abuse
xX420mlgnoscopeXx is not online. xX420mlgnoscopeXx
Joined: 28 Nov 2015
Total Posts: 73
15 May 2015 12:41 PM
HEEEEEEEEEEEEEEEEEEEEEEEELP
Report Abuse
powerhotmail123 is not online. powerhotmail123
Joined: 11 Apr 2011
Total Posts: 5041
15 May 2015 12:42 PM
Tables!
Report Abuse
xX420mlgnoscopeXx is not online. xX420mlgnoscopeXx
Joined: 28 Nov 2015
Total Posts: 73
15 May 2015 12:53 PM
can you say something more than 1 word pls
maybe teach me how to do that instead of saying what to use without any explanation
Report Abuse
gIuton is not online. gIuton
Joined: 21 Apr 2015
Total Posts: 102
15 May 2015 12:54 PM
sounds = {sound1, sound1, sound3, sound4}

while true do
--play sounds here
end


Ey you like my sombrero? | rip hiddenreporter
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 01:15 PM
local soundIDs = {1337, 9001, 300}
local sound = Instance.new("Sound", game.Workspace")
local intermissionTime = 10

while true do
local ranSoundID = soundIDs[math.random(1, #soundIDs)]
sound.SoundId = "rbxassetid://"..ranSoundID
sound:Play()
wait(sound.TimeLenght)
sound.SoundId = "rbxassetid://"
wait(intermissionTime)
end
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
15 May 2015 01:15 PM
@instawin while wait() do*
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 01:16 PM
made some typos

fix them yourself m8
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 01:17 PM
@time

no, my while loop doesn't need a wait() for the condition

it already has some waits in there already, it won't crash the game.
Report Abuse
TheNewChicken is not online. TheNewChicken
Joined: 18 Mar 2015
Total Posts: 1997
15 May 2015 01:18 PM
@insta

Less lag, fixed some typos..

local soundIDs = {0000,0000,0000,0000}
local Sound = Instance.new("Sound",workspace)
local IntermissionTime = 10

for i = 1,math.huge do
local ranSoundID = soundIDs[math.random(1, #soundIDs)]
Sound.SoundId = "rbxassetid://"..ranSoundID
Sound:Play()
wait(Sound.TimeLength)
Sound.SoundId = "rbxassetid://"
wait(IntermissionTime)
end
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 01:20 PM
"for i = 1,math.huge do"

..

that's the exact same as an infinite while loop, and all you did was plop my script into it

it's the exact same thing as my while loop
Report Abuse
TheNewChicken is not online. TheNewChicken
Joined: 18 Mar 2015
Total Posts: 1997
15 May 2015 01:22 PM
No its not.

i used workspace which is more efficient
i fixed a few typos, find them yourself

I made some of the looks a bit better

also a numerical for loop is more efficient, too

read up, buddy. i tried to be nice.
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 01:28 PM
"i used Workspace, more efficient"

true, but barely
it's a trivial amount of time saved, barely noticeable

"numerical for loops are more efficient"

i'd like to know where you heard this

"fix your own typos"

he's lucky i even gave him a free script
Report Abuse
TheNewChicken is not online. TheNewChicken
Joined: 18 Mar 2015
Total Posts: 1997
15 May 2015 01:28 PM
numerical for loops are.
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 01:29 PM
"i'd like to know where you heard this" [2]
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
15 May 2015 01:32 PM
@insta while wait() do is proper noob.
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 01:33 PM
@time

it's a thing of preference
Report Abuse
TheNewChicken is not online. TheNewChicken
Joined: 18 Mar 2015
Total Posts: 1997
15 May 2015 01:42 PM
@insta

wow. quoting yourself to try to get noobs to agree.

You are a terrible scripter.
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 01:46 PM
"wow. quoting yourself to try to get noobs to agree.

You are a terrible scripter."

lol wtf
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
15 May 2015 01:59 PM
@TheNewChicken:
while true do is better than for i = 1, math.huge

1) i will eventually overflow, and become math.huge, and math.huge == math.huge == true, so that loop isn't infinite
2) If you look at the bytecode (luac -l -p in terminal) http://pastebin.com/bEksayYD
Lua knows while true is infinite, so can just jump back to the start, however it can't say that about for loops so has to keep evaluating the parameters.
Report Abuse
Intern33t is not online. Intern33t
Joined: 19 Nov 2010
Total Posts: 1530
15 May 2015 02:00 PM
though i have to say i always rather use

for i = 1, math.huge do
print(i)
end

than

local i = 1
while wait() do
i = i + 1
print(i)
end
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 02:03 PM
@droid

actually i do have a question

how long would it take for i to be equal to math.huge?
Report Abuse
instawin is not online. instawin
Joined: 04 Jun 2013
Total Posts: 8777
15 May 2015 02:05 PM
actually i'll test that out right now
Report Abuse
Dr01d3k4 is not online. Dr01d3k4
Joined: 11 Oct 2007
Total Posts: 17916
15 May 2015 02:07 PM
@insta: Hm idk. I'm not sure of the size of numbers Lua uses (i.e. 32 bit or 64 bit), and whether math.huge is just defined as 2^(32|64) and bigger. However I do know this happens - I once wrote a train system that used for i = 1, math.huge and after playing in the server for a while, the trains just stopped working.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image