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: How do you spawn blocks with math.random????

Previous Thread :: Next Thread 
PinkFlamess is not online. PinkFlamess
Joined: 29 Jun 2014
Total Posts: 9
20 Jul 2017 09:06 PM
Eyo! I'm working on a 2-d platformer with my bro and decided to work on a script that involves higher-point coins having a higher spawn chance as you progress through the game. The main problem is that I don't know how to make these coins even spawn, not to mention the whole higher-chance-spawn stuff. I've been looking everywhere about spawning, but block themselves (except for vehicle spawners) are nowhere to be found. I just started coding on the Roblox engine yesterday, but my bro said he doesn't know either (he's slightly better than me at coding). Here's what I have so far for the script:

t = time
r = math.random(if t < 100 or t = 100, then r < 20 or r = 20
if 100 < t < 130 or t = 130, then 10 < r < 30 or r = 30
if 130 < t < 200 or t = 200, then 20 < r < 40 or r = 40
if 200 < t < 300 or t = 130, then 45 < r < 80 or r = 80
if 300 < t < 345 or t = 400, then 60 < r < 85 or r = 85
if 345 < t < 410 or t = 410, then 70 < r < 90 or r = 90
if 410 < t < 430 or t = 430, then 90 < r < 95 or r = 95
if 430 < t < 530 or t = 530, then 95 < r < 100 or r = 100
if t > 530 , then r = 100)
end

r < 10 or r = 10, then SBronze
10 < r < 25 or r = 15, then SSilver
25 < r < 50 or r = 50, then SGold
50 < r < 75 or r = 75, then SPlatnium
r > 75, then SRainbow
end
end

SRainbow =
SPlatnium =
SGold =
SSilver =
SBronze =

I don't know what to put for the last 5 lines (these are the five coins, each having their varying value. The S before each coin-type means spawn. The crazy if, then statements is me attempting to put my ideas into code)

Thanks!
Report Abuse
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
20 Jul 2017 09:30 PM
I think this is what you intended:

t = time -- not sure if you meant the time built-in function here
local lrand = 0
local urand = 0
if t <= 100 then
urand = 20
elseif t <= 130 then
lrand = 10
urand = 30
elseif t <= 200 then
lrand = 20
urand = 40
elseif t <= 300 then
lrand = 45
urand = 80
elseif t <= 345 then
lrand = 60
urand = 85
elseif t <= 410 then
lrand = 70
urand = 90
elseif t <= 430 then
lrand = 90
urand = 95
elseif t <= 530 then
lrand = 95
urand = 100
else
lrand = 100
urand = 100
end
local r = urand - (urand-lrand)*math.random()
local coin = SBronze
if r > 75 then
coin = SRainbow
elseif r > 50 then
coin = SPlatinum
elseif r > 25 then
coin = SGold
elseif r > 10 then
coin = SSilver
end

SRainbow = -- ??? Don't know what you want here
SPlatnium =
SGold =
SSilver =
SBronze =
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
20 Jul 2017 10:12 PM
Lua doesn't support A < B < C
You can only do one of those operations at a time.
Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
20 Jul 2017 10:14 PM
You can't place an 'if' in the arguments in the math.random() function, you can use ternary operations tho

Also, math.random() doesn't need an 'end'


Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
PinkFlamess is not online. PinkFlamess
Joined: 29 Jun 2014
Total Posts: 9
21 Jul 2017 09:39 AM
Thanks! You guys are awesome. I'll see if it works Bunny (The SRainbow etc are unnecessary now that I see what you've done in the code.) So will this replace a physical object with the object I want based on the probability?
Report Abuse
PinkFlamess is not online. PinkFlamess
Joined: 29 Jun 2014
Total Posts: 9
21 Jul 2017 09:47 AM
Also, what measurement does the time (function?) use? (ex. Milliseconds, seconds, minutes etc.)
Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
21 Jul 2017 11:39 AM
Use the wiki man, that's why it exists.

http://wiki.roblox.com/index.php?title=Global_namespace/Roblox_namespace#time


Roblox.Forum.Scripters:1: bad argument #1 to 'intellect' (number expected, got nil)
Report Abuse
marfit is online. marfit
Joined: 10 Jan 2013
Total Posts: 2539
21 Jul 2017 12:02 PM
Just have a loop that when each block is created, its position is math.random in every direction. For the color, you can have a table that selects colors based on their corresponding number with math.random. For material, same thing,
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