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: Math.random help

Previous Thread :: Next Thread 
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 06:42 PM
I made a script so that with random numbers generated, the block (an ore) changes materials and such. But they all wind up exactly the same. If one block was selected as "Copper", the rest are coppers.

Can anyone help me fix the script without having to change the variable m=math.random

math.randomseed(tick())

local m=math.random(1,1000)

if m > 0 and m < 400 then
script.Parent.BrickColor=BrickColor.new("Dirt brown")
script.Parent.Material="Concrete"
script.Parent.BlockValue="Dirt"
end

if m > 400 and m < 600 then
script.Parent.BrickColor=BrickColor.new("Rust")
script.Parent.Material="Ice"
script.Parent.BlockValue="Copper"
end

if m > 600 and m < 750 then
script.Parent.BrickColor=BrickColor.new("Institutional white")
script.Parent.Material="Ice"
script.Parent.BlockValue="Silver"
end

if m > 750 and m < 900 then
script.Parent.BrickColor=BrickColor.new("CGA brown")
script.Parent.Material="Slate"
script.Parent.BlockValue="Iron"
end

if m > 900 and m < 950 then
script.Parent.BrickColor=BrickColor.new("New Yeller")
script.Parent.Material="Ice"
script.Parent.BlockValue="Gold"
end

if m > 950 and m < 975 then
script.Parent.BrickColor=BrickColor.new("Pastel Blue")
script.Parent.Material="Ice"
script.Parent.BlockValue="Diamond"
end

if m > 975 and m < 985 then
script.Parent.BrickColor=BrickColor.new("Eggplant")
script.Parent.Material="Granite"
script.Parent.BlockValue="Obsidian"
end

if m > 985 and m < 990 then
t=Instance.new("PointLight")
script.Parent.BrickColor=BrickColor.new("Really red")
script.Parent.Material="Cobblestone"
script.Parent.BlockValue="Adurite"
t.Parent=script.Parent
t.Brightness=5
t.Color=Color3.new(255,0,0)
t.Range=10
end

if m > 990 and m < 995 then
a=Instance.new("PointLight")
script.Parent.BrickColor=BrickColor.new("Forest green")
script.Parent.Material="Pebble"
script.Parent.BlockValue="Viridian"
a.Parent=script.Parent
a.Brightness=5
a.Color=Color3.new(85,170,0)
a.Range=10
end

if m > 995 and m < 999 then
g=Instance.new("PointLight")
h=Instance.new("Fire")
script.Parent.BrickColor=BrickColor.new("Dark blue")
script.Parent.Material="Foil"
script.Parent.BlockValue="Bluesteel"
g.Parent=script.Parent
g.Brightness=5
g.Color=Color3.new(0,0,255)
g.Range=10
h.Parent=script.Parent
h.Heat=3
h.Color=Color3.new(0,0,255)
h.SecondaryColor=Color3.new(0,0,255)
h.Size=13
end

if m > 999 and m < 1001 then
k=Instance.new("Sparkles")
script.Parent.BrickColor=BrickColor.new("Black")
script.Parent.Material="Cobblestone"
script.Parent.BlockValue="Black Iron"
k.Color=Color3.new(85,0,255)
end



Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
13 Apr 2016 06:45 PM
I think to fix this you'd have to reverse the if statements. This can probably be simplified too. But anyway try that, do the harder ones first, then do the easy ones
Report Abuse
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 06:48 PM
what do you mean reverse?


Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
13 Apr 2016 06:49 PM
Like, the if statements on the bottom, bring those to where the if statement for Dirt is. You know, swap them. Hard to explain.
Report Abuse
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 07:00 PM
Doesn't work. I reversed the orders of the if statements, and my first test on the game was 10 copper blocks.

and copper isnt even the most common ore ;-;


Report Abuse
eRanged is not online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
13 Apr 2016 07:06 PM
this isn't the problem but, you should use elseif instead of keep repeating if



Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
13 Apr 2016 07:08 PM
^ You're right, and it is the problem...
Report Abuse
eRanged is not online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
13 Apr 2016 07:09 PM
olol



Report Abuse
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 07:16 PM
still doesnt work...

all 8 blocks came out as iron, which is not supposed to be common.i changed the if statements to elseifs, excluding the first if statement of course.


Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
13 Apr 2016 07:18 PM
You mean like this?

math.randomseed(tick())

local m=math.random(1,1000)

if m > 0 and m < 400 then
script.Parent.BrickColor=BrickColor.new("Dirt brown")
script.Parent.Material="Concrete"
script.Parent.BlockValue="Dirt"

elseif m > 400 and m < 600 then
script.Parent.BrickColor=BrickColor.new("Rust")
script.Parent.Material="Ice"
script.Parent.BlockValue="Copper"

elseif m > 600 and m < 750 then
script.Parent.BrickColor=BrickColor.new("Institutional white")
script.Parent.Material="Ice"
script.Parent.BlockValue="Silver"

elseif m > 750 and m < 900 then
script.Parent.BrickColor=BrickColor.new("CGA brown")
script.Parent.Material="Slate"
script.Parent.BlockValue="Iron"

elseif m > 900 and m < 950 then
script.Parent.BrickColor=BrickColor.new("New Yeller")
script.Parent.Material="Ice"
script.Parent.BlockValue="Gold"

elseif m > 950 and m < 975 then
script.Parent.BrickColor=BrickColor.new("Pastel Blue")
script.Parent.Material="Ice"
script.Parent.BlockValue="Diamond"

elseif m > 975 and m < 985 then
script.Parent.BrickColor=BrickColor.new("Eggplant")
script.Parent.Material="Granite"
script.Parent.BlockValue="Obsidian"

elseif m > 985 and m < 990 then
t=Instance.new("PointLight")
script.Parent.BrickColor=BrickColor.new("Really red")
script.Parent.Material="Cobblestone"
script.Parent.BlockValue="Adurite"
t.Parent=script.Parent
t.Brightness=5
t.Color=Color3.new(255,0,0)
t.Range=10

elseif m > 990 and m < 995 then
a=Instance.new("PointLight")
script.Parent.BrickColor=BrickColor.new("Forest green")
script.Parent.Material="Pebble"
script.Parent.BlockValue="Viridian"
a.Parent=script.Parent
a.Brightness=5
a.Color=Color3.new(85,170,0)
a.Range=10

elseif m > 995 and m < 999 then
g=Instance.new("PointLight")
h=Instance.new("Fire")
script.Parent.BrickColor=BrickColor.new("Dark blue")
script.Parent.Material="Foil"
script.Parent.BlockValue="Bluesteel"
g.Parent=script.Parent
g.Brightness=5
g.Color=Color3.new(0,0,255)
g.Range=10
h.Parent=script.Parent
h.Heat=3
h.Color=Color3.new(0,0,255)
h.SecondaryColor=Color3.new(0,0,255)
h.Size=13

elseif m > 999 and m < 1001 then
k=Instance.new("Sparkles")
script.Parent.BrickColor=BrickColor.new("Black")
script.Parent.Material="Cobblestone"
script.Parent.BlockValue="Black Iron"
k.Color=Color3.new(85,0,255)
end
Report Abuse
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 07:19 PM
its exactly like that.


Report Abuse
eRanged is not online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
13 Apr 2016 07:19 PM
What activates that function? Like a TouchedEvent or just a onetime script? Because it shouldn't be making 8 bricks.



Report Abuse
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 07:20 PM
There are 8 identical bricks with the same script.

The script just runs i guess, there's no specific function for it. What I pasted is the entire script.


Report Abuse
eRanged is not online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
13 Apr 2016 07:21 PM
Or do you already have 8 different bricks with 8 different scripts?



Report Abuse
eRanged is not online. eRanged
Joined: 15 Jun 2013
Total Posts: 9746
13 Apr 2016 07:22 PM
oh, sorry ninja'd. Also do each brick have this script in each brick? You could try testing with while wait(5) do



Report Abuse
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 07:23 PM
They all have the same, identical script, and I will test with wait do.


Report Abuse
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 07:28 PM
The blocks all have the same script, and all turned into a silver block.

Logically, I should change the "m" variable, but I'm going to have a large amount of mineable blocks, so it would be too hard for me.


Report Abuse
lululukas is not online. lululukas
Joined: 23 Aug 2010
Total Posts: 1043
13 Apr 2016 07:33 PM
math.randomseed(tick()) is the problem, idk why but with it it always picks the same number, without it it works.
Report Abuse
Deathying is not online. Deathying
Joined: 21 Aug 2015
Total Posts: 1425
13 Apr 2016 07:40 PM
thank you so much lukas!!!

:)))))

scripters forum is going in place credits


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