Region3 Instance Spawns Way Off

Hey guys, I tried making a region and then making an Instance to visualize that region, but it sadly doesn’t spawn in the right position. It still spawns in the right size though. Please help, thank you!

local point2 = game.Workspace.Point2 -- Point 1 & 2 are in the white zone.
local point1 = game.Workspace.Point1 -- Their positions are [(-12.735, 31.292, 72.565) & (86.265, 130.289, 171.565)]

local Region1 = Region3.new(point1.Position, point2.Position)

local part = Instance.new("Part")

part.Anchored = true
part.CanCollide = false
part.Size = Region1.Size
part.Parent = game.Workspace


(The grey part is meant to be in the white area…)

1 Like

You need to change your existing positions into the min and your max versions of themselves with math.min() and math.max(). Here’s an example.

local NewRegion = Region3.new(
				Vector3.new(
					math.min(v.Point1.Position.X, v.Point2.Position.X),
					math.min(v.Point1.Position.Y, v.Point2.Position.Y),
					math.min(v.Point1.Position.Z, v.Point2.Position.Z)
				),
				Vector3.new(
					math.max(v.Point1.Position.X, v.Point2.Position.X),
					math.max(v.Point1.Position.Y, v.Point2.Position.Y),
					math.max(v.Point1.Position.Z, v.Point2.Position.Z)
				)
			)

(Sorry for the formatting this was copied from a large block)

You did not set the CFrame of the part; therefore, it is spawning at the origin.

2 Likes

I tried setting its CFrame, but that didn’t work [ERROR Line 3: CFrame cannot be assigned to]

local Region1 = Region3.new(Vector3.new(-12.735, 31.292, 72.565),Vector3.new(86.265, 130.289, 171.565))

Region1.CFrame = CFrame.new(36.265, 31.292, 122.065)

local part = Instance.new("Part")

part.Anchored = true
part.CanCollide = false
part.Size = Region1.Size
part.Parent = game.Workspace

You do not set the Part CFrame to the CFrame of the region3.

1 Like

I know that. The part is only meant to help visualize where the region is located. Now I want to move my region3 except I don’t know how to…

In your code, just add part.CFrame = Region1.CFrame, preferably before or after setting part.Size for organization. This will set the CFrame (Orientation and Position) of the part to the one of the Region3.

I’m not sure I understand how that would work. wouldn’t that just set the Part CFrame to the Region CFrame?

I tried it with the script below and it didn’t change anything: the part is still in its original position.
Keep in mind the part generated only represents the Region and is here only for testing purposes the referred part (for the Region3 position) is r1

local r1 = game.Workspace.Regions["1"]

local Region1 = Region3.new(Vector3.new(-12.735, 31.292, 72.565),Vector3.new(86.265, 130.289, 171.565))

r1.CFrame = Region1.CFrame

local part = Instance.new("Part")

part.Anchored = true
part.CanCollide = false
part.Size = Region1.Size
part.Parent = game.Workspace

You need to set the CFrame of the part you want to represent the region3, if you want to have less trouble, you can just use the solution to this post. Part To Region3 Help?
Which allows you to simply create a region3 that englobes the area the part takes up.

local Region1 = Region3.new(Vector3.new(-12.735, 31.292, 72.565),Vector3.new(86.265, 130.289, 171.565))

Region1.CFrame = CFrame.new(36.265, 31.292, 122.065)

local part = Instance.new("Part")

part.Anchored = true
part.CanCollide = false
part.Size = Region1.Size
part.Parent = game.Workspace
part.CFrame = Region1.CFrame  ----- You need to set the new part's Cframe, your region was positioned properly, the part was not.
1 Like

Ohhhhhh… I understand now. Though that doesn’t seem to be the solution, since the ERROR is still there saying Line 5: CFrame cannot be assigned to.

This seems to mean I can’t set a CFrame to a Region3, although that should be possible, right?

local r1 = game.Workspace.Regions["1"]

local Region1 = Region3.new(Vector3.new(-12.735, 31.292, 72.565),Vector3.new(86.265, 130.289, 171.565))

Region1.CFrame = CFrame.new(36.265, 31.292, 122.065)

local part = Instance.new("Part")

part.Anchored = true
part.CanCollide = false
part.Size = Region1.Size
part.Parent = game.Workspace
part.CFrame = Region1.CFrame

No, you do not need to set the CFrame of the Region3. Simply use this code:

local point2 = game.Workspace.Point2 -- Point 1 & 2 are in the white zone.
local point1 = game.Workspace.Point1 -- Their positions are [(-12.735, 31.292, 72.565) & (86.265, 130.289, 171.565)]

local Region1 = Region3.new(point1.Position, point2.Position)

local part = Instance.new("Part")

part.Anchored = true
part.CanCollide = false
part.Size = Region1.Size
part.CFrame = Region1.CFrame
part.Parent = game.Workspace

Like this man said. I forgot to remove that line, my bad.