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

Way to detect if a player is not in a region3?

Asked by 3 years ago

Hi, I'm trying to detect if there is a player that is not in region3, but I don't understand how!

01local Region = Region3.new(Vector3.new(258, -47, -99), Vector3.new(348, -23, 99))
02 
03local Workspace = game:GetService("Workspace")
04 
05while wait(1) do
06 
07    local PartsInRegion = Workspace:FindPartsInRegion3(Region)
08 
09    for _,Child in pairs(PartsInRegion) do
10 
11        if Child:IsA("BasePart") then
12 
13            local BasePart = Child
14 
15            if BasePart and BasePart.Parent then
View all 37 lines...

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

Hello Bankrovers,

My name is YelloMynamesZak and I'd be happy to help you with your problem.

You could try this: Make a part that represents the region. After you're done, name it "Region".

Then, put a localscript in StarterCharacterScripts and type the following:

01local Touching = false
02local part = workspace.Region
03part.Touched:Connect(function()
04    Touching = true
05    print("Player is  in region")
06end)
07part.TouchEnded:Connect(function()
08    Touching = false
09    print("Player is NOT in region")
10end)

This’ll work for a local script. If this is a server sided script then you can make a table which has each user’s ID as the index, and the value equal to false. Set it equal to true upon touching the part, then set it to false upon the touch ending. It's much more simpler than the code you provided and can be connected to server scripts via remote events.

Please reply to this answer is you're facing any issues.

Hope this helps!

0
Works! Bankrovers 226 — 3y
0
Make sure to add you code to that script and have fun! Glad it worked! YelloMynamesZak 85 — 3y
Ad

Answer this question