-
I’m trying to make a tycoon and make the droppers work in one script using a function and a for loop. The script does run the function but only for one “producer”.
-- module
local TycoonModule = require(script.Parent.TycoonModule)
-- variables
local Tycoon = script.Parent
local StartingProducers = Tycoon.StartingItems.Producers
local ClaimedEvent = Tycoon.ClaimedEvent
-- function
function ProducerScript(Producer, Owner, OwnerData)
local ResourceProduced = Producer:FindFirstChild("ResourceProduced").Value
local ProducedAmount = Producer:FindFirstChild("ProducedAmount").Value
local OwnerResource = OwnerData:FindFirstChild(ResourceProduced)
while Producer:GetAttribute("Active") do
OwnerResource.Value = OwnerResource.Value + ProducedAmount
wait(Producer:GetAttribute("IntervalTime"))
end
end
ClaimedEvent.Event:Connect(function()
for index, producer in pairs(StartingProducers:GetChildren()) do
producer:SetAttribute("Active", true)
task.spawn(ProducerScript(producer, TycoonModule.TycoonOwner, TycoonModule.TycoonOwnerData))
end
end)
- I’ve asked ai and looked around but cant seem to find anything, please help!