Making part not get past plot border

I have a plot system and tool that moves the part,but i want to make the part stop when player is trying to get it out of the plot

i tried many things like .Touched and rays but nothing of it worked

this is the tool code:

local plr = game.Players.LocalPlayer
local mode = "Move"
local UIS = game:GetService("UserInputService")
local mouse = plr:GetMouse()
local hand


mouse.Button1Down:Connect(function()
	if mouse.Target ~= nil and mode == "Move" and mouse.Target.Parent.Parent.Name == plr.Name then
		if hand ~= nil then
			hand:Destroy()
		end
		hand = script.Handles:Clone()
		hand.Parent = plr.PlayerGui
		hand.Adornee = mouse.Target
		mouse.Button1Up:Connect(function()
			script.Parent.RemoteEvent:FireServer(hand.Adornee.CFrame,hand.Adornee,hand.Adornee.Size)
		end)
		script.Parent.Unequipped:Connect(function()
			hand:Destroy()
		end)
		mouse.Button1Down:Connect(function()
			hand:Destroy()
		end)
	elseif mode == "Rotate" and mouse.Target ~= nil and mouse.Target.Parent.Parent.Name == plr.Name then
		if hand ~= nil then
			hand:Destroy()
		end
		hand = script.ArcHandles:Clone()
		hand.Parent = plr.PlayerGui
		hand.Adornee = mouse.Target
		mouse.Button1Up:Connect(function()
			script.Parent.RemoteEvent:FireServer(hand.Adornee.CFrame,hand.Adornee,hand.Adornee.Size)
		end)
		script.Parent.Unequipped:Connect(function()
			hand:Destroy()
		end)
		mouse.Button1Down:Connect(function()
			hand:Destroy()
		end)
	elseif mode == "Resize" and mouse.Target ~= nil and mouse.Target.Parent.Parent.Name == plr.Name then
		if hand ~= nil then
			hand:Destroy()
		end
		hand = script.Handles2:Clone()
		hand.Parent = plr.PlayerGui
		hand.Adornee = mouse.Target
		mouse.Button1Up:Connect(function()
			script.Parent.RemoteEvent:FireServer(hand.Adornee.CFrame,hand.Adornee,hand.Adornee.Size)
		end)
		script.Parent.Unequipped:Connect(function()
			hand:Destroy()
		end)
		mouse.Button1Down:Connect(function()
			hand:Destroy()
		end)
	end
end)

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Z then
		mode = "Move"
		if hand ~= nil then
			local adorn = hand.Adornee
			hand:Destroy()
			hand = script.Handles:Clone()
			hand.Parent = plr.PlayerGui
			hand.Adornee = adorn
		end
	elseif input.KeyCode == Enum.KeyCode.X then
		mode = "Rotate"
		if hand ~= nil then
			local adorn = hand.Adornee
			hand:Destroy()
			hand = script.ArcHandles:Clone()
			hand.Parent = plr.PlayerGui
			hand.Adornee = adorn
		end
	elseif input.KeyCode == Enum.KeyCode.C then
		mode = "Resize"
		if hand ~= nil then
			local adorn = hand.Adornee
			hand:Destroy()
			hand = script.Handles2:Clone()
			hand.Parent = plr.PlayerGui
			hand.Adornee = adorn
		end
	end
end)

this is code inside Handles

Handles = script.Parent
local Part
local CF
local increment = 0.2
Handles.MouseButton1Down:connect(function()
	Part = Handles.Adornee
	CF = Part.CFrame
end)
Handles.MouseDrag:Connect(function(face, dist)
	local moving = Handles.Adornee
	local axi = {
		[Enum.NormalId.Right] = moving.CFrame.RightVector,
		[Enum.NormalId.Left] = -moving.CFrame.RightVector,
		[Enum.NormalId.Top] = moving.CFrame.UpVector, 
		[Enum.NormalId.Bottom] = -moving.CFrame.UpVector,
		[Enum.NormalId.Front] = moving.CFrame.LookVector,
		[Enum.NormalId.Back] = -moving.CFrame.LookVector,
	}
	moving.CFrame = CF + axi[face] * (math.floor(dist / increment) * increment)
end)

Have you tried to Raycast and check if the part is in the plot, then if it’s not you will be unable to place. ( Seems easy enough )

so the part im moving with will have raycast and whenever the raycast stops detecting the plot the part handles will dissappear? it might work if there were raycasts in all the four corners of the part

If a plot is a simple box shape then there are easy ways to do it, but if it can be more complex shapes then it requires a more complex solution.

the plot is just a simple box

30 30 30 30 30 30