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!