The current drops in my tycoon fall extremely slowly eventually. I assume this is because of the load I’m putting the server under? I’ve even tried using object pooling, where I recycle the drops I’m using, but even that doesn’t work. Is there a better way to optimise the drops in a tycoon that completely eliminates the problems I’m having?
These are the common optimisations for tycoon drops, from what I can tell:
- Setting the network ownership of the drops to the player. This moves the load from the server to the client.
- Tweening the drops, where possible. If they land on a conveyor and the path is predictable - tween it! This prevents the need for physics simulation (assuming you turn off CanCollide and anchor the parts)
- Reduce the number of drops.
I’ve tried setting network ownership and it doesn’t do anything. I’m unsure of how exactly I’d tween the drops, and I have already tried reducing the number of drops using object pooling (essentially I’m cloning drops, and instead of destroying these drops when they are collected they are recycled for other droppers).
While reusing the drops would help, what I meant is reducing the number of drops that are active at once, which can be achieved by decreasing the drop rate of the droppers in the tycoon. To tween the drops, you could check for them to hit a conveyor, then wait a second for them to stabilise. Then, tween them towards the collection area.
Alright, lemme try decreasing the drop rate. All the youtube tutorials I’ve watched never have this same problem even tho they don’t tween whatsoever. Here’s a video of what it looks like, if that gives you any extra ideas:
Can you try testing it an actual server instead of Studio please
Alright. --Minimum characters needed
I’d argue it’s worse
That low FPS is most likely caused by something else. Can you check if disabling the droppers entirely dramatically improves performance?
(I will be AFK for 30 minutes)
This is what it looks like… Performance definitely improved at first, but after leaving it for a bit it started to slow down to how it was before:
probably a memory leak of some sorts, check your code for inefficient coding
How can I identify a memory leak(like what are common ways memory leaks happen). Also what is a memory leak?
i dont understand it too well, but (i think) it’s when some really inefficient coding eats up your RAM and makes your game run horribly
Not sure if its a memory leak if the memory is stays relatively the same. The ping is constantly rising tho
Edit: I might be wrong, the memory is rising but its rising relatively slowly. I think the server is just lagging over time as the ping started at 60ms but has risen to 3000ms
As @Exozorcus said, the fact that it gradually becomes more laggy over time suggests a memory leak. Can you please send the code you are using to spawn the drops in?
Also, if you press Ctrl + Shift + 7 and watch the memory usage there, does it go up at all
local DropsModels = ServerStorage.Drops
local Modules = ServerScriptService.Modules
local DropperInfo = require(Modules.DropperInfo)
local TycoonInfo = require(Modules.TycoonInfo)
local Drops = workspace.Drops
local Dropper = {}
Dropper.__index = Dropper
local PossibleTouchParts = {
"Plunge",
"Source",
"Conveyor",
"Part",
"Sensor",
"Drop",
"Crab",
"Seahorse",
"Starfish",
"UpgraderPart",
"Wedge"
}
function Dropper:End()
setmetatable(self, nil)
table.clear(self)
table.freeze(self)
end
local function getDrop(player: Player)
if TycoonInfo.PooledDrops[player] then
for index, drop in TycoonInfo.PooledDrops[player] do
table.remove(TycoonInfo.PooledDrops[player], index)
return drop
end
end
return nil
end
function Dropper:DropTouched(drop: BasePart | Model, hit: BasePart)
if not table.find(PossibleTouchParts, hit.Name) then
--print(hit.Name)
if not hit.Parent:FindFirstChild("Humanoid") then
drop.Parent = ServerStorage.PooledDrops
end
end
end
function Dropper:Drop()
local offset = -1.25
local dropperModel = self.Dropper
local drop = getDrop(self.Owner)
if drop ~= nil then
if drop:IsA("Model") then
drop:MoveTo(dropperModel.Drop.Position + Vector3.new(0, offset, 0))
else
drop.Position = dropperModel.Drop.Position + Vector3.new(0, offset, 0)
end
else
drop = DropsModels:FindFirstChild(self.DropType):Clone()
if drop:IsA("Model") then
local parentPart = drop.Part
parentPart.CollisionGroup = "Drop"
for _, part in parentPart:GetChildren() do
if part:IsA("BasePart") then
part.CollisionGroup = "Drop"
end
end
drop:SetAttribute("Value", self.Info.DropValue)
drop:MoveTo(dropperModel.Drop.Position + Vector3.new(0, offset, 0))
parentPart.Touched:Connect(function(hit)
self:DropTouched(drop, hit)
end)
else
drop.CollisionGroup = "Drop"
drop:SetAttribute("Value", self.Info.DropValue)
drop.Position = dropperModel.Drop.Position + Vector3.new(0, offset, 0)
drop.Touched:Connect(function(hit)
self:DropTouched(drop, hit)
end)
end
end
drop.Parent = Drops:FindFirstChild(self.Owner.Name)
end
function Dropper:Init()
self.Info = DropperInfo[self.Dropper:GetAttribute("Type")]
self.Dropper.Drop.Transparency = 1
self.DropType = self.Tycoon:GetAttribute("DropType")
for _, part in self.Dropper:GetDescendants() do
if part:IsA("BasePart") then
part.CollisionGroup = "Dropper"
end
end
end
function Dropper.new(tycoon: Model, dropper: Model, owner: Player)
local self = {}
setmetatable(self, Dropper)
self.Tycoon = tycoon
self.Dropper = dropper
self.Owner = owner
self:Init()
if self.Info ~= nil then
task.spawn(function()
while self.Dropper ~= nil and self.Info ~= nil do
self:Drop()
task.wait(self.Info.DropDelay)
end
end)
end
tycoon.Destroying:Connect(function()
self:End()
end)
return self
end
The ctrl + shift + 7 keyboard shortcut you showed me isn’t anything. Shift lock is disabled. I’m viewing the server through console and memory is slowly rising, so a memory leak might be happening
I got the shortcut wrong - It should have been with an F7.
So Ctrl + F7 (I always do a shift as well out of habit, but it isn’t needed)
I can confirm the memory is rising through the menu that came up. Ping is also increasing/is very high in general. Can you see anything wrong just from my code?
Not immediately seeing any issues with it.
If you add
if true then return end
to the first line of the :Drop() function (line 53), does the memory leak still occur?