I’m going to be having a lot of moving objects in my game, moved via CFrame. I’ll be using BulkMoveTo as it’s noted as being the fastest method of updating large amounts of objects.
I have created a module that registers an object, and returns a reference to its index within the table.
I can now use this index to update the CFrames, or to remove it.
I add an Update function inside this module to call workspace:BulkMoveTo() on the tables it has stored within itself at the end of .Heartbeat
This seemingly works for a very small amount of objects. But whenever it grows slightly, any removals crash roblox.
This only appears to happen while Update is also being called in the code (Commenting it out seems to result in no crashes.)
ReproBulkMoveBug.rbxl (25.9 KB)
BulkMove Module
local BulkMove = {}
local Objects, CFrames = {}, {}
function BulkMove.AddToList(Object, CF)
local Placement = 0
for i, _ in pairs(CFrames) do
Placement = i
end
Placement += 1
table.insert(Objects, Placement, Object)
table.insert(CFrames, Placement, CF)
--print(#Objects, #CFrames)
return Placement
end
function BulkMove.UpdateCFrame(ID, CF)
CFrames[ID] = CF
end
function BulkMove.RemoveItem(ID)
print("Removing;", ID)
CFrames[ID] = nil
Objects[ID] = nil
end
function BulkMove.Update()
workspace:BulkMoveTo(Objects, CFrames)
end
return BulkMove
All code is found within the PlayerScripts, tapping the button will create a new ExampleObject.
I don’t know if this is a legitimate bug, or if this is something I’ve overlooked in my coding.