I have a script that checks region3 for parts in model “hag” every .5 seconds, however no matter how many waits I add into the loop, I get “game script timeout” error. I’m not sure what this means, as without the loop the script only checks region3 once.
Here’s my code.
local part = script.Parent
local min = part.Position - (2.5 * part.Size)
local max = part.Position + (2.5 * part.Size)
local region = Region3.new(min, max)
local parts = workspace:FindPartsInRegion3WithWhiteList(region, {workspace.hag}, 20) -- ignore part
function lol()
for _, part in pairs(parts) do
if part.Name == "e81" then print "found"
part.BrickColor = BrickColor.new("Really black") else print "nothing"
end
end
end
while true do
function lol()
wait()
end
end
You’re creating a new function within the infinite loop instead of calling the function. You can call a function by putting 2 parenthesis next to the function name like so: lol() instead of function lol() ... end and it’ll run the code within the function.
Also, the reason your script is timing out is because the infinite loop is executing the code faster than the timeout limit. You can mitigate this by calling wait within your infinite loop.
I’m not sure how I missed that lol, however I still have the issue of the function only finding and changing the properties of one brick, and nothing else.
Try creating the Region3 for every loop iteration and see if the parts are detected then like so:
local part = script.Parent
function lol()
local min = part.Position - (2.5 * part.Size)
local max = part.Position + (2.5 * part.Size)
local region = Region3.new(min, max)
local parts = workspace:FindPartsInRegion3WithWhiteList(region, {workspace.hag}, 20) -- ignore part
for _, part in pairs(parts) do
if part.Name == "e81" then
print "found"
part.BrickColor = BrickColor.new("Really black")
else
print "nothing"
end
end
end
while true do
wait(1)
lol()
end