I tried almost about everything to spawn a part randomly inside region3.
I’m kind of stumped here since am still learning Lua, right now I’m trying to increase my knowledge when it comes to math in coding. I’m still new to this region3 stuff, thank you very much.
6/28/2022 2:28PM
local e = workspace.Region3Folder.E
local f = workspace.Region3Folder.F
local newPart = Instance.new("Part")
local region = Region3.new(e.Position, f.Position)
local clone = f:Clone()
clone.CFrame = region.CFrame
clone.BrickColor = BrickColor.new("New Yeller")
clone.Transparency = 0.5
clone.Parent = workspace
clone.Size = region.Size
clone.Name = "RegionPart"
clone.CanCollide = false
newPart.Parent = workspace.Region3Folder
newPart.Name = "Cool"
wait(4)
newPart.Anchored = true
local Workspace = workspace
local Part1 = Workspace.Part1
local Part2 = Workspace.Part2
local RandomObject = Random.new()
local function RandomPoint(P1, P2, A) --Part1, Part2, Axis.
return RandomObject:NextNumber(math.min(P1.Position[A], P2.Position[A]), math.max(P1.Position[A], P2.Position[A]))
end
local function SpawnRandomPart(P1, P2)
local Part = Instance.new("Part")
Part.Position = Vector3.new(RandomPoint(P1, P2, "X"), RandomPoint(P1, P2, "Y"), RandomPoint(P1, P2, "Z"))
print(Part.Position)
Part.Parent = Workspace
end
for _ = 1, 10 do
SpawnRandomPart(Part1, Part2)
end