Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Generate random numbers without math.randomseed?

Here below is the script. I have a 8 blocks in Workspace, which have the same identical script. I cannot use math.randomseed(tick(), or math.randomseed in general, because that would affect every single block. Basically, if math.randomseed generates the number 4, all the other blocks will have 4.

Without math.randomseed, the blocks generate as different things, but don't change when you rejoin the server.

Any way I can fix this?

m=math.random(1,1000)
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)


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 > 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 > 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 > 975 and m < 985 then
	script.Parent.BrickColor=BrickColor.new("Eggplant")
	script.Parent.Material="Granite"
	script.Parent.BlockValue="Obsidian"

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

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

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

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

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

1 answer

✓ Accepted answer

I'm a tad bit confused by what you mean, but here's a possible solution to your problem. Keep the exact same script you currently have, but put this line of code at the very beginning. Change NOTHING else. This'll make it so that the blocks shouldn't be exactly the same every time you join the server.

math.randomseed(tick()%1*1e6)
--everything else you had, starting from m=math.random(1,1000)

It worked for me when I made a procedural generating dungeon. Why? I'm not perfectly sure, but as far as I'm aware it's because it sort-of updates the math.random function so that it works correctly.

2 comments

0

You deserve a medal, good sir!

0

<3, I ran into the same problem 4 months ago and this was how it was solved. Happy to spread knowledge!

This discussion is preserved as it was. New answers, comments, and votes are closed.