I am working on a tycoon where, like all other tycoons, it resets when a player leaves.
When a player leaves or rebirths, the tycoon resets. The tycoon uses OOP, and the actual tycoon model gets added to a janitor, and when the tycoon clears/resets, it deletes the janitor, which deletes any instances and disconnects any active connections
function tycoon:Reset(rebirth:boolean)
for index,value in pairs(tycoonObjects) do
if value == self then
table.remove(tycoonObjects,index)
end
end
local team = self.Team
local owner = self.owner
local clone = self.clone
local parent = self.parent
self.janny:Destroy()
clone.Parent = parent
if rebirth and owner then
local stats = owner:FindFirstChild("leaderstats")
if stats then
local rebirths:IntValue = stats:FindFirstChild("Rebirths")
local cash:IntValue = stats:FindFirstChild(cashName)
if rebirths then
cash.Value = cashGiver:Rebirthed(owner)
rebirths.Value += 1
end
end
replicatedStorage.events.client.sound:FireClient(owner,"rebirth")
data:Clear(owner,self.role)
tycoon.new(clone,team,owner)
else
tycoon.new(clone,team)
end
setmetatable(self, nil)
table.clear(self)
table.freeze(self)
end
There are about 5.4k parts in each tycoon, with about 6.7k other instances (models etc.).
When the tycoons are deleted and respawned into the game, there are noticeable ping spikes. Usually the ping will go from 50-150ms to about 250-500ms and then quickly go back to “normal,” but sometimes I’ve seen it hit upwards of 3000+ ping.
How can I optimize deleting and respawning tycoons so the pings aren’t crazy?