Building Physics: Game script timeout?

I’m currently working on a battle royale game and the building works fine until I come to breaking stuff. It causes a game script timeout and I’m not sure if it’s me or and engine bug (probably me). It happens at line 31 where I find the touching parts then check them from the ignore list. The “BuildCheck()” function is called when I break a building(wall, ramp etc.).

Heres the script:

local BuildService = {Client = {}}
local positions = {
	Wall = {};
	Ramp = {};
	Floor = {};

local function contains(list, item) 
	local contains = false
	for _,v in pairs(list) do -- ERRORS HERE
		if v== item then
			contains = true
	return contains

local function GetTouchingParts(instance, ignorelist)
	local parts = instance:GetTouchingParts()
	local list = {}
	for _,v in pairs(parts) do
		if not contains(ignorelist, v) then
			table.insert(list, v)
	return list

local function getplaceable(cf,obj, ignorelist)
	local placeable = false
	if ignorelist == nil then
		ignorelist = {}
	local causeof = nil
	local build = game.ReplicatedStorage.Aero.Builds[obj]:Clone()
	build.Parent = workspace.Builds
	for _,v in pairs(GetTouchingParts(build.Part, ignorelist)) do
		if v.Parent:IsA("Model") then
			if v.Parent.Parent == workspace.Builds then
				placeable = true
				causeof = v.parent
		elseif v.Parent:IsA("Folder") then
			if v.Parent == workspace.Map then
				placeable = true
	return placeable, causeof

local function BuildCheck()
	local i, why = nil, workspace.Builds:GetChildren()[1]
	local checked = {}
	local before = why
	i, why = getplaceable(why.CF.Value, why.Name, checked)
	table.insert(checked, before)
	until (i and why == nil) or (i == false)
	if i == false then
		print("Not held up")
	elseif i == true and why == nil then
		print("Held up")

Then whenever I run it, all I get is this error:

 11:17:05.842 - ServerStorage.Aero.Services.BuildService:45: Game script timeout
11:17:05.843 - Stack Begin
11:17:05.843 - Script 'ServerStorage.Aero.Services.BuildService', Line 32 - upvalue contains
11:17:05.843 - Script 'ServerStorage.Aero.Services.BuildService', Line 45 - upvalue GetTouchingParts
11:17:05.844 - Script 'ServerStorage.Aero.Services.BuildService', Line 61 - upvalue getplaceable
11:17:05.844 - Script 'ServerStorage.Aero.Services.BuildService', Line 83 - upvalue BuildCheck
11:17:05.844 - Script 'ServerStorage.Aero.Services.BuildService', Line 155 - method Remove
11:17:05.845 - Script 'ServerStorage.Aero.Services.GunService', Line 57 - upvalue func
11:17:05.845 - Script 'ServerScriptService.Aero.Internal.AeroServer', Line 81
11:17:05.845 - Stack End

and then I tried printing the touching parts, and I got this:

just keeps going.

Hope I can get some help!


It’s when you do so many calculations without any yield. There’s a timeout to prevent infinite loops.

If you have a lot of parts and do expensive checks, or you do a lot of recursion, consider putting a yield in there. Perhaps create a counter and yield briefly for every 1000 cycles in your loop. Or better yet, move to an event-based model if you can structure your game accordingly.

Unfortunately you’ve not included where you call the BuildCheck function from, so it’s hard to advise you any further as to whether it’s a recursive issue or just a huge table with expensive calcs on each iteration.

I’ve run into it before when playing around with looping through a huge map (hundreds of thousands of parts) and do various checks and setup and reparenting on each one without any yields. It’s generally a sign of you doing unnecessary work or overly expensive work that probably doesn’t need to happen all in the exact same instant without any yield.


It is called once and it should only be performing 2 calculations. When i look at it unless i have invisible part (which i dont) there should only be 2 other parts but it checks the same one over and over again

Not sure from immediately looking at it. I’d put a print at the start of each function printing its name and its arguments which may help to identify if there’s any strange looping back and forth or if this is happening in a single iteration.

So like

local function getplaceable(cf,obj, ignorelist)
    print( 'getplaceable', 'cf', cf, 'obj', obj, 'ignorelist', ignorelist )

Once you’ve got the output of that, it may be easier to start narrowing down where the issue is.

ok ill get on it(30characters)

oh. This might have something to do with it:Capture02
it seems to be checking the same wall over and over again.
Keep in mind, there is only 1 build placed atm

Any thoughts on why the ignore list aint working?

I think you’d need to print i, why, before to know for sure. It’s clearly working, and finding those two touching parts, so it’s a case of understanding why the loop doesn’t exit.

Side note: Logically isn’t
until (I and why == nil) or (I==False)
equivalent to
until (I==False) or (why == nil)