It's not immediately evident what is causing this issue, as it sporadically occurs and has no stack trace.
However, I can guarantee the issue doesn't occur if I never enable this script.
local kart = script.Parent:WaitForChild("GoKart")
local regen_model = kart:Clone()
local rig
local cons = {}
local function regen()
local new = regen_model:Clone()
new.Parent = script.Parent
rig(new)
end
rig = function(k)
local chute = k:WaitForChild("KartChute")
game.Debris:AddItem(chute, math.random(8, 12))
for _,con in cons do con:Disconnect() end cons = {}
-- Wrap signal connections in pcall and add error handling
local success, err = pcall(function()
table.insert(cons,k.Destroying:Connect(regen))
table.insert(cons,k.AncestryChanged:Connect(function()
if k.Parent == nil then
regen()
end
end))
end)
if not success then
warn("Error connecting signals:", err)
end
end
-- Wrap rig function call in pcall and add error handling
local success, err = pcall(function()
rig(kart)
end)
if not success then
warn("Error in rig function:", err)
end
Despite wrapping the only execution points in pcall, the error occurs and is not caught, which I guess implies it's happening outside of the script somehow?
A clone of this script is created and then placed per new gokart variant and Enabled so it can execute after the parent has been initialized to workspace.