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
break
end
end
return contains
end
local function GetTouchingParts(instance, ignorelist)
local parts = instance:GetTouchingParts()
local list = {}
for _,v in pairs(parts) do
print(v)
if not contains(ignorelist, v) then
table.insert(list, v)
end
end
return list
end
local function getplaceable(cf,obj, ignorelist)
local placeable = false
if ignorelist == nil then
ignorelist = {}
end
local causeof = nil
local build = game.ReplicatedStorage.Aero.Builds[obj]:Clone()
build:SetPrimaryPartCFrame(cf)
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
end
elseif v.Parent:IsA("Folder") then
if v.Parent == workspace.Map then
placeable = true
end
end
end
build:Destroy()
return placeable, causeof
end
local function BuildCheck()
local i, why = nil, workspace.Builds:GetChildren()[1]
local checked = {}
repeat
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")
else
print("Error")
end
end
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!