Hi, I’ve recently made a Tycoon game and I’ve been having problems combating the memory usage. My PhysicsCollision & PhysicsParts memory usage is slowly going up. My dropper script assigns a PhysicsCollision group to every dropper part it makes, so the dropped parts can’t collide with eachother. Is destroying the dropper part not enough?
I have a part that the dropper parts will eventually touch & get destroyed, which looks like this
local values = script.Parent.Parent.Parent.Parent:WaitForChild("values")
local moneyValue = values:WaitForChild("moneyValue")
local processed = setmetatable({}, { __mode = "k" })
local function onTouched(hit)
-- dropperpart check
if not hit or not hit:IsA("BasePart") or hit.Name ~= "DropperPart" then
return
end
-- debounce per-instance
if processed[hit] then
return
end
processed[hit] = true
-- clean up when part is destroyed
local destroyingConn
destroyingConn = hit.Destroying:Connect(function()
processed[hit] = nil
if destroyingConn then
destroyingConn:Disconnect()
destroyingConn = nil
end
end)
-- increase moneyValue
local dropValue = hit:FindFirstChild("MoneyValue")
if dropValue and dropValue:IsA("IntValue") and hit.Parent then -- verify
moneyValue.Value += dropValue.Value
hit:Destroy()
end
end
script.Parent.Touched:Connect(onTouched)
I’ve tried removing the assigned physicscollision group, but that somehow made the memory leak greater before destroying the dropper part.
I believe the PhysicsParts memory usage is a Roblox engine issue (as far as I’ve seen), and nothing much I can do about that. Am I doing something very wrong with my code?
Thanks for any possible suggestions!