How can I check if a Vector3 is within a certain area?

I’m making a building game and intend to implement plots. In order to do this, I need to check if a Vector3 submitted by the player is within a certain cube-shaped area.

Here is a function which determines whether a Vector3 position is in an area.

local function IsPositionInPart(Position, Part) -- Vector3,Instance
	local RelPosition = Part.CFrame:PointToObjectSpace(Position)
	if math.abs(RelPosition.X) <= Part.Size.X/2 and math.abs(RelPosition.Y) <= Part.Size.Y/2 and math.abs(RelPosition.Z) <= Part.Size.Z/2 then
		return true
	return false

This is how you use it…

local Part ="Part")
Part.Size =, 10, 10)
Part.Position =, 0, 0)
local inputPosition =, 0, 0)
local inArea = IsPositionInPart(inputPosition, Part)
Part:Destroy() -- Optional, you could also resort to making a table for the Position and Size
warn("inArea = " .. tostring(inArea))

The output should look like this

> inArea = true

You could use Raycasting for this where you can Whitelist the cubed area using:

And that will be the only part where the raycast will register and you’ll be able to place the block.

Thank you so much for the help!