Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[ANSWERED] Math.random is affecting all bricks with the same script?

Asked by
Suamy 68
8 years ago

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

2 answers

Log in to vote
0
Answered by 8 years ago

fam it is a simple mistake with your Variables

Example

local ran = math.random(1,1000)
print(ran)

when i run that script the number is gonna be random 1,1000 and no matter how many times i do

print(ran)

the number is still gonna be the same if you don't know what i'm talking about the make a script put it in workspace then run it

local ran = math.random(1,1000)
print(ran)
print(ran)
print(ran)
print(ran)
print(ran)
print(ran)
print(ran)

when you run it u see how the the numbers are the exact same? it is the same with yours. When you run this script the numbers are truly random

local ran = math.random(1,1000)
local ban = math.random(1,1000)
local pan = math.random(1,1000)
local gan = math.random(1,1000)
local fan = math.random(1,1000)
local can = math.random(1,1000)
print(ran)
print(ban)
print(pan)
print(gan)
print(fan)
0
oops i made a mistake just copy the script underneath the 3rd paragraph and run it bradleyawsome 10 — 8y
0
This does NOT answer my question at all. You didn't even include math.randomseed(tick()) which makes truly random numbers. Please explain properly. Suamy 68 — 8y
Ad
Log in to vote
0
Answered by
Suamy 68
8 years ago

math.randomseed(tick() needs to be removed, in order for the script to work. Thanks for the answer.

0
congrats scottmike0 40 — 8y
0
Am I seeing things or did you just give an answer to your question? 0_0 70 — 8y
0
I found out the answer on my own, so I decided to put the answer here to prevent wasting other people's time with this question. Suamy 68 — 8y

Answer this question