Hi, So right now I’m currently working on a Dropper Type System for a Game, and I was wondering about Properly Managing Dropper Times, and when to fire them.
Most of the time when I see Tycoon Games, their Droppers Contain a Script Within every single one of them, and they contain a while
loop inside of them telling them when to drop, something like this:
while task.wait(script.Parent:GetAttribute("Rate")) do -- loops
DropObject:Invoke(i, DropType)
-- Typically three is no BindableFunction
end
Pretty Simple, but not very efficient in the long run.
So Im my Attempts, I have a Script that Tags an Object Under a Specific Name, and gives it a piece of Data to use when it comes for that usage, The Following is essentially the Script that Controls the Droppers, and their Data:
(I used Parallel Luau here, but I dont know if it is a good utilization of it)
(It is also Managed by the Server, with a few Exceptions)
local Tag = "Droppers" -- Tag to use
CollectionService:GetInstanceAddedSignal(Tag):ConnectParallel(i)
if not i:IsA("BasePart") then -- To Ensure we are getting the right objects
task.synchronize() -- Runs in Serial
i:RemoveTag(Tag) -- Removes Tag
return
end
DropperData[i] = {os.clock(), i:GetAttribute("Rate")} -- Adds Data
end)
RunService.Heartbeat:ConnectParallel(function()
local Collection = CollectionService:GetTagged(Tag) -- Gets Instances
if #Collection < 1 then return end -- Stops if Collection is Empty
for _,i in next, Collection do -- iterates through Collection
local Data = DropperData[i] -- Gets Dropper Data
if not Data then continue end -- Skips if no Dropper Data
local Elapsed = os.clock() - (Data[1] or 0) -- Elapsed Time
if Elapsed < Data[2] then continue end -- Skips if time not reached
local DropType = i:GetAttribute("Type") -- Grabs Dropper Type
Data[1] = os.clock() -- Resets Time
task.synchronize() -- Runs in Serial
DropObject:Invoke(i, DropType) -- Invokes BindableFunction to Drop Item
end
end)
It appears to work as Intended, but I’m wondering if this is the best way to actually do this? Because I have seen other methods where people use Object Oriented Programming for this.
Would this be better?