How to detect if a part is in a zone or not

Hi, I’m working on a part-movement tool.
The way it works is to move the parts locally and send the moved parts and the location values of the parts to the server and apply them on the server as well.

스크린샷 2024-06-16 131004
스크린샷 2024-06-16 131011

I want the parts to be moved only within a certain area.
So the way I thought of it was to use Region 3 to apply the part position when the part position value is within the zone position, and to return the part position to the pre-movement position when it is outside the position.
However, as far as I know, Region 3 is no longer used. So I need an alternative, and I don’t know what to do.
Please help…

This code is the code that will be the base for that functionality.

local toolEvent = ReplicatedStorage:WaitForChild("ToolEvent")

toolEvent.OnServerEvent:Connect(function(player, target, newCFrame)
	local originPosition = target.Position
	local testpart = TierModel.testpart
	if target and newCFrame then
		target.Position = newCFrame
	end
end)

A better choice to Region3 is using :GetPartsInPart(), which detects any parts that enter the part. This won’t work if the zone area has the CanCollide property set to true. Here’s an example of how it should look like.

local Part = game.Workspace:WaitForChild("ee") -- change to your part
local FilterParts = {} -- anything you want to be filtered

local Params = OverlapParams.new() -- add more to the params if you want
Params.FilterType = Enum.RaycastFilterType.Exclude
Params:AddToFilter(FilterParts)

while task.wait() do
	local PartsInPart = game.Workspace:GetPartsInPart(Part, Params)
	
	for Index, DetectedPart in pairs(PartsInPart) do
		if DetectedPart.Name == Part.Name then continue end
		
		if DetectedPart.Name == "YourPartName" then -- change this to your part's name
			print("Success!")
		end
	end
end
2 Likes

Perhaps you could use ZonePlus v3.2.0 | Construct dynamic zones and effectively determine players and parts within their boundaries - Resources / Community Resources - Developer Forum | Roblox and simply check whether the parts new position is inside the zone, if not then clamp back to the last valid position or reject the new position entirely

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.