Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
14dark14 167
4 years ago

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
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. Ziffixture 6913 — 4y
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. Infocus 144 — 4y
0
Sorry I didn't see someone replied already Infocus 144 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago
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

Ad

Answer this question