Why are my droppers dispending so slowly?

My droppers are dispensing extremely slowly and my ping is through the roof. Why is this happening?

Here is my code for the droppers:

local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService('ServerStorage')
local TweenService = game:GetService('TweenService')

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] > 0 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
		
		print('creating new drop')
		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
	
	if drop then
		drop.Parent = Drops:FindFirstChild(self.Owner.Name)
	end
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

return Dropper

Any help would be appreciated!

3 Likes

try rendering the dropped items only on the client via a remoteevent when its created

1 Like

Alright, I’ll try that. How would I detect the conveyor touching the part that is created on the client? Would I use some mathematics to calculate the time that it would take?

is it possible fro u to send a video of it

what do you mean?

extracharacters bruhhh




How would I know when to give the player their cash?

Based on the conveyor speed and the length

I’ve done this. In the end, it always ends up slowing down. I’m not sure if its because I’m running 2 clients at once and I have a bad computer, or because of the game itself.

I’m not sure how much it will help, but I notice you are creating a new touched event for each cash part. Would it not be more efficient to just attach the event to the cash processor part?

With each of those touched events, and the amount of parts, it must be firing like crazy.

Also I notice that the touch event never gets disconnected. You seem to store the part back to ServerStorage after it’s done with? (I don’t think that would disconnect the signal)

You can optimize this in 2 ways i’d say:

  1. Make the dropped items purely visual, they are emitted from the client at a constant rate and have no control over how you win money, the server will simply give you a constant amount of money depending on the upgrades you have (with some slight random variation)
  2. Through an UnreliableRemoteEvent, communicate to the client at which dropper to emit an item, and the server will calculate when to give the player their money with some pretty basic math (taking into account the distance from the dropper to the seller and the conveyor speed)

You should also make these droppers only emit their items, or send an event to emit these items, when the player is currently at that floor

Another thing you could do is calculate the physics for each item yourself (as all you do here is drop an item from a height to the conveyor and then the conveyor moves the item linearly) for even more optimization and to disable collisions between the items

1 Like

Just have a local script that’ll detect when it touches the cash making part and send a remote event to the server to give the cash.

try to Set Networkship Network Ownership | Documentation - Roblox Creator Hub

oh its just dropping slower cause of how laggy u are