How would I Make a block Randomly spawn in a bigger area Than 500 Studs [Unsloved]

I have been having Problems coding a random spawning block that goes further than 500 in Position

for i = 1,500 do
		local cloned = game.workspace.Part:Clone()
	cloned.Position = Vector3.new(math.random(100,1509),-210.5,math.random(100,1509))
	end

Expectation is to scatter blocks all over that area
All it does is Spawn in one 1/4 of the area i wanted it to spawn in any ideas on how to make it spawn in 100% of the area any Answers would be heavily Appreciated!

Your problem is that with the numbers that you put into the function, you will only get parts put into one quadrant, Quadrant I. There are two ways that this can be done. The first and easiest is to just change your bounds on the math.random to be -1509, 1509 for both of them. This will work, but then the parts will be created in the zone from 0-100 which does not happen with the current code. If that is going to be a problem, then you can just generate a random sign as will be shown below.

One other thing that may cause problems is that with math.random you are limited to integers (whole numbers) while if you use Random.new() and use the object returned from that with :NextNumber you will be able to get float (decimal number) results.

-- Random.new
local rng = Random.new()
--...
Position = rng:NextNumber(-1509, 1509)...
-- way 1
Position = Vector3.new(math.random(-1509, 1509), -210.5, math.random(-1509,1509))
-- way 2
local sign1 = math.random(0, 1)
if sign1 == 0 then
	sign1 = -1
end
local sign2 = math.random(0, 1)
if sign2 == 0 then
	sign2 = -1
en
Position = Vector3.new(sign1 * math.random(100,1509),-210.5,sign2 * math.random(100,1509))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.