I am looking for some insight on my issue that crashes the whole game. I have experienced this before while developing, however since then I improved my code and I thought this issue was resolved, however today I looked at an “Error Report” for my game and I saw this error again:
“Script timeout: exhausted allowed execution time”
This is my ModuleScript that I require in a Script that starts up with server:
local CollectionService = game:GetService("CollectionService")
local LightsServer = {}
local function getBaseModel(instance)
local itemsFolder = instance:FindFirstAncestorOfClass("Folder") -- This is the line the error is pointing to
if not itemsFolder then
return
end
local baseModel = itemsFolder.Parent
local ownerName = baseModel:GetAttribute("Owner")
if not ownerName then
return
end
return baseModel
end
CollectionService:GetInstanceAddedSignal("Light"):Connect(function(instance)
local baseModel = getBaseModel(instance)
if not baseModel then
return
end
local modelLightInstances = LightsServer.LightInstances[baseModel]
if not modelLightInstances then
modelLightInstances = {}
LightsServer.LightInstances[baseModel] = modelLightInstances
end
modelLightInstances[instance] = true
instance.AncestryChanged:Connect(function(child, parent)
if not parent then
modelLightInstances [instance] = nil
end
end)
local ownerName = baseModel:GetAttribute("Owner")
local owner = Players:FindFirstChild(ownerName)
if owner then
local success, playerSettings = _G.DataServer:GetData(owner, "Settings"):await()
if success then
instance.Enabled = playerSettings.Lights
end
end
end)
return LightsServer
My suspicions are that this problem is caused because there are like 10000+ instances with the tag “Light” in the ServerStorage, however this might also be a red herring, because they are already tagged and the signal should not fire. Also, the line the error is pointing to shouldn’t take that long to execute to cause this error either, so I would love to hear more opinions. ![]()