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 » Scripting Helpers
Home Search
 

Re: Choosing Random Model

Previous Thread :: Next Thread 
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
23 Jan 2012 05:57 PM
What would i do to choose a random model from a model in lighting?
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
23 Jan 2012 05:58 PM
math.Random?

† KMXD †
Report Abuse
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
23 Jan 2012 06:00 PM
yes, i know i need math.random, but how would i sue that to find a random model from a model in lighting?
Report Abuse
MXrcr20 is not online. MXrcr20
Joined: 01 Oct 2008
Total Posts: 2644
23 Jan 2012 06:01 PM
models = game.Lighting:GetChildren()
i = math.random(1,10)

if i == 1 then
game.Lighting.Model1:clone().Parent = workspace
end

if i == 2 then
game.Lighting.Model1:clone().Parent = workspace
end

etc...
Report Abuse
MXrcr20 is not online. MXrcr20
Joined: 01 Oct 2008
Total Posts: 2644
23 Jan 2012 06:01 PM
"models = game.Lighting:GetChildren()"
Whoops. Forgot to take that out. I was going to do something else...
Report Abuse
Cyrok is not online. Cyrok
Joined: 11 Jan 2012
Total Posts: 630
23 Jan 2012 06:03 PM
    math.randomseed(tick())

    function returnModel()
        local modelTable = {}
        local lightingChildren = game:GetService("Lighting"):GetChildren()
        for index, value in pairs(lightingChildren) do
            if value:IsA("Model") then
                table.insert(modelTable, value)
            end
        end
        local randomModel = math.random(1, #modelTable)
        return randomModel
    end

    local modelObject = returnModel()

{ I have an OCD when it comes to non-camelCase variables/custom functions. }
Report Abuse
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
23 Jan 2012 06:05 PM
thats what i was going to do before, but im need it to choos one thin g randomly and then anoither thin randomly. Which is why i wanted to know how to choose a random model from lighting. If i dont do this, my script will be very inefficent.
Report Abuse
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
23 Jan 2012 06:09 PM
My last post was a responce to MXrcr20.
Report Abuse
xvgigakid is not online. xvgigakid
Joined: 22 Jun 2008
Total Posts: 4407
23 Jan 2012 06:12 PM
@Unholy

Here is a really simple way to do this.

lighting = game.Lighting:GetChildren()
num = math.random(1, #lighting)
object = lighting[num]:clone() --Random Model Has Been Cloned.
Report Abuse
KnightmareXD is not online. KnightmareXD
Joined: 14 Jul 2009
Total Posts: 11189
23 Jan 2012 06:13 PM
@Xv But what if has other things in Lighting?

† KMXD †
Report Abuse
unholysoda is not online. unholysoda
Joined: 15 May 2010
Total Posts: 9024
23 Jan 2012 06:28 PM
ok, thanks for the help
Report Abuse
xvgigakid is not online. xvgigakid
Joined: 22 Jun 2008
Total Posts: 4407
23 Jan 2012 06:36 PM
@Knightmare

Well he could place all of the models that he wants to be randomly selected in a DIFFRENT Instance.
Then place that Instance inside lighting. Then do

I = Instance:GetChildren()
--Blah Blah.

Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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