Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to see if someone has left region3? ( Advance )

Ok this is quite advance, I made a region3 script that detects when a player is in the area and how to do I detect when the player has left the area?

local regoin = Region3.new(Vector3.new(1,1,1), Vector3.new(9,9,9))
local part = Instance.new("Part", game.Workspace)
part.Anchored = true
part.Size = regoin.Size
part.CFrame = regoin.CFrame
part.CanCollide = false
part.Transparency = .5
while true do	
wait(1)
     local regionparts = workspace:FindPartsInRegion3(regoin, part, 100)
        for i, part in pairs(regionparts) do
	     if part.Parent:FindFirstChild("Humanoid") ~= nil then
		print(part.Parent.name)
	 end
   end
end

3 comments

0

You should use runService to call :FindPartsInRegion3() perpetually. You can also build an array containing the allocated Humanoid then verify on the next Render to see if there isn't a part within the found Instances that matches the Humanoid stored anymore.. Adjust the arrays accordingly.

0

Haven't messed around with Region3 yet, but I know it has FindPartsInRegion3, which I'm assuming you can get to your player. I would log/record the player then check whether or not the player is present within the area. Easy to say, but its a different thing to do it. I'm just assuming that's how its done.

0

Sorry I didn't see someone replied already

1 answer

✓ Accepted answer
local runService = game:GetService("RunService")
local regoin = Region3.new(Vector3.new(1,1,1), Vector3.new(9,9,9))
local part = Instance.new("Part")
part.Parent = workspace
part.Anchored = true
part.Size = regoin.Size
part.CFrame = regoin.CFrame
part.CanCollide = false
part.Transparency = .5
local wasFound = false
runService.RenderStepped:Connect(function()
	local found
    local regionparts = workspace:FindPartsInRegion3WithWhiteList(regoin, game.Players.LocalPlayer.Character:GetDescendants(), 100)
    for i, v in next, regionparts do
    	if v:IsDescendantsOf(game.Players.LocalPlayer.Characrer) then
			found = true
			wasFound = true
			break
		end
	end
	if not found and wasFound then
		print("player left area")
		wasFound = false
	end
end)

edit: formatting

This discussion is preserved as it was. New answers, comments, and votes are closed.