Hello, for some reason it is hard for me to make blocks fall in random positions within the area of a block … could someone help me?
For this, you can simply generate random number for each of the x, y, and z values found in positions. Simply create a part you want to model as the area, and set it to the first variable.
local area = --Define part here
local function getRandomPos(part) --Function to call to get the position, will be different every time
local min = part.Position - (part.Size/2)
local max = part.Position + (part.Size/2)
local rx = math.random(min.X,max.X) --Get the x, between the max and min
local ry = math.random(min.Y,max.Y) --Get the y, between the max and min
local rz = math.random(min.Z,max.Z) --Get the z, between the max and min
return Vector3.new(rx, ry, rz)
end
local randPos = getRandomPosInArea(area)
print(randPos) --Print random position in the area, use this to spawn parts ect.
local part = Instance.new("Part") --Spawn part at random position
part.Position = randPos
part.Parent = workspace
9 Likes