How to detect if player entered/left region3?

Hi this is my script and this wont detect player in region3, idk why …

local point1 = workspace.Point1
local point2 = workspace.Point2

local region = Region3.new(point1.Position,point2.Position)
local players = {}

local part = Instance.new("Part",workspace)
part.Anchored = true
part.CanCollide = false
part.Transparency = 0.3
part.Size = Vector3.new(98.015, 6.703, 8.349)
part.CFrame = region.CFrame

while true do
	wait(1)
	local partsInRegion = workspace:FindPartsInRegion3(region, part, 1000)
	for i, part in pairs (partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			print('You are in region!: ', part.Parent.Name)
		end
	end
end
1 Like

You should tell us if theres errors, not just say “it wont work”.

Can you label any errors in the output?

i dont have any erros in the output thats why i saying ’ it wont work ’

Also, instead of using
Instance.new("Part",parent)
use:
part.Parent = --whatever
in a seperate line

local part = Instance.new(“Part”,workspace)

part.Anchored = true

part.CanCollide = false

part.Transparency = 0.3

part.Size = Vector3.new(98.015, 6.703, 8.349)

part.CFrame = region.CFrame

Elaborate what you’re trying to do. Part is finding child humanoid but humanoid isnt a valid child of Workspace, its a child of the player.

Man i need help from programmer so if you dont know anything about region3 and tables/loops please do not reply non sense

1 Like
local pos1 = part.Position - (part.Size / 2 + Vector3.new(0,0,0))
local pos2 = part.Position + (part.Size / 2 + Vector3.new(0,50,0))
local region = Region3.new(pos1, pos2)

game:GetService("RunService").Stepped:Connect(function()
    for i,v in pairs(workspace:FindPartsInRegion3(region, part, math.huge)) do
        if v.Parent:FindFirstChild("Humanoid") then
           print('You are in region!: ', v.Parent:FindFirstChild("Humanoid").Parent.Name)
        end
    end
end)

You need to set the positions. Also play around with the Vector3 value of the region positions. Also better to use .Stepped rather than while true do

4 Likes

It clearly isnt my fault, just dont say it doesnt work, find the problem and tell us whats not working, also your script is poorly written, and most likely from a youtube tutorial. You’re using deprecated functions, like workspace and ,parenthere. Please do not say its nonsense as im trying to help you, and I hope it did help you.

Thank you. I was confused about the “while true do”

You asking:

What is part when you have answer in script
You say Part is finding child humanoid but humanoid isnt a valid child of Workspace, its a child of the player when part is character part that hitted region3

its non sense

Your answer will help me much, thank you!

workspace is not deprecated. It is a global, actually it is more encouraged to use workspace than game.Workspace since it is faster.

2 Likes

and how would i make it work with FindPartsInRegion3WithWhitelist and detect when a player leaves the region