When Inside of a zone

I am trying to make it so that when an NPC with a Specific Name enters the union, the NPC will slow down and will begin to subtract 1 health per 0.01 of a second

I don’t know how to come upon this task, HELP!

For checking if the user is within the region, one solution is you can use workspace:GetPartsInParts(), which will return a table of parts within the region. However, I find it fairly inaccurate.

I had your exact same issue when creating a map kit for my game, but I solved it using the following formula:

local a = workspace.PartA    -- The part you are using as a region
local b = workspace.PartB    -- The part you want to check if it is within the region.

local c = a.CFrame.LookVector*(b.Position - a.Position)    -- Checking Z axis
local d = a.CFrame.RightVector*(b.Position - a.Position)    -- Checking X axis
local e = a.CFrame.UpVector*(b.Position - a.Position)       -- Checking Y axis

if math.abs(c.X + c.Z) + b.Size.Z/2 < a.Size.Z/2 then 
     if math.abs(d.X + d.Z) + b.Size.X/2 < a.Size.X/2
          if math.abs(e.Y) + b.Size.Y/2 < a.Size.Y/2 then 
               -- PartB is officially within the region of PartA
          end
    end 
end

I use this formula quite often, and it works quite accurately. You’ll have to have it in a loop, though, so it is constantly checking. However, this will not work with unions or MeshParts.

Hello! This is actually simple, so basically inside of the zone say this:

script.Parent.Touched:Connect(function() end) -- Reason is because we needed to make a touchinterest in the part

while true do 
	task.wait()
	local GetPartsInZone = script.Parent:GetTouchingParts()
	
	for i,v in pairs(GetPartsInZone) do
		if v.Parent:FindFirstChild("Humanoid") then
			local CharacterFound = v.Parent
			warn("Found: "..CharacterFound.Name)
		end
	end
end
2 Likes