Hey,
I have a script thats supposed to detect if an object goes into the region, and run code once. However I need to constantly check if the part became a part of the region. So I made a while loop and a value so it runs once. However, how do I make the value reset once the part leaves the region? I tried the code below but it ran the code with the loop instead of once, so basically while its in the region its constantly running the code (a print function). Sorry if Im bad at explaining things.
local part = script.Parent
local region = Region3.new(script.Parent.Position - (script.Parent.Size / 2),script.Parent.Position + (script.Parent.Size / 2))
local runService = game:GetService("RunService")
local ranOnce = false
while true do
local PartsInRegion = workspace:FindPartsInRegion3(region, nil, math.huge)
for i,v in pairs(PartsInRegion) do
if v.Name == "AIGhost" then
if ranOnce == false then
ranOnce = true
print("IT ENTERED THE ZONE")
end
else
ranOnce = false
end
end
runService.Stepped:Wait()
end