Is there a way to detect if player is no longer in a region because the else statement in the script below doesn’t work and I tried doing if not Part.Parent:FindFirstChild(“Humanoid”) but that didn’t work either. If you know how, please let me know.
local RegionPart = script.Parent
local pos1 = RegionPart.Position - (RegionPart.Size/2)
local pos2 = RegionPart.Position + (RegionPart.Size/2)
local Region = Region3.new(pos1,pos2)
local TestValue = script.Parent.Parent.TestValue
local runOnce = 1
local runOnce2 = 1
while wait(1) do
local partsInRegion = workspace:FindPartsInRegion3(Region, nil, math.huge)
local playersInRegion3 = {}
for i, Part in pairs(partsInRegion) do
if Part.Parent:FindFirstChild("Humanoid") then
if runOnce == 1 then
runOnce = runOnce + 1
TestValue.Value = true
print("works")
end
local plyrs = game.Players:FindFirstChild(Part.Parent.Name)
table.insert(playersInRegion3,plyrs)
Part.Parent.Humanoid:TakeDamage(1)
else
if runOnce2 == 1 then
runOnce2 = runOnce2 + 1
TestValue.Value = false
print("this works too")
end
end
end
end