AutoCollect for Zed‘s Tycoon Kit

Hello. So, I‘ll explain, how to make an AutoCollect “Button/Gamepass” for @Zed_Gaming’s Tycoon Kit (also works with @TwinPlayzDev 's Tycoon Kit)
First: we need to open the Model’s (TycoonKit → Tycoons → NameOfTycoon )

Now we have to script. Insert in every Tycoon a script.
script

I am trying to explain it well, please don’t judge me

local cooldown = 1
local Owner = script.Parent.Owner

Here we created two local variables! The cooldown is for the time you get Cash (here one second). The second one is the Owner.

while task.wait(cooldown) do
end)

Here, we created a loop. This will basically make this: wait cooldown, do code, wait cooldown and so on.

while task.wait(cooldown) do 
if Owner.Value ~= nil and script.Parent.PurchasedObjects:FindFirstChild("AutoCollect") then
end
end)

We checked here, if the Owner exists and if he bought our Button, that we’ll create later.

while task.wait(cooldown) do 
if Owner.Value ~= nil and script.Parent.PurchasedObjects:FindFirstChild("AutoCollect") then
if game.Players:FindFirstChild(tostring(Owner.Value)) then 
local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(game.Players:FindFirstChild(tostring(Owner.Value)))
if Stats ~= nil then 
end
end
end
end)

Here we check another time if the player really exists, we created the “Stats” Variable and checked if the “Stats” Variable isn’t nil.

Stats.Value = Stats.Value += script.Parent.CurrencyToCollect.Value 
script.Parent.CurrencyToCollect.Value = 0 

So past this under “if Stats ~= nil then”.

The entire code
while task.wait(cooldown) do 
if Owner.Value ~= nil and script.Parent.PurchasedObjects:FindFirstChild("AutoCollect") then
if game.Players:FindFirstChild(tostring(Owner.Value)) then 
local Stats = game.ServerStorage.PlayerMoney:FindFirstChild(game.Players:FindFirstChild(tostring(Owner.Value)))
if Stats ~= nil then 
Stats.Value = Stats.Value += script.Parent.CurrencyToCollect.Value 
script.Parent.CurrencyToCollect.Value = 0 
end
else 
print("No plr Found") -- Just ignore/delete that
end
end
end)

Now make a Button in “Buttons” with Object=AutoCollect (best: make a int-Value called “Gamepass” with your Gamepass Id). Then Make an Model (best is nothing inside) in “Purchases” that you call “AutoCollect”.

If that was too much for you, you can get the Model here.

6 Likes

and for a tutorial not the best either, fairly short addition, mine is 5 lines, this however

Critique

  • Instead of nesting if-statements, use the logical operator and instead.
  • Instead of spamming FindFirstChild and if-statements, use variables for object paths and allow the user to configure it themselves
  • Instead of using while task.wait(1), connect a function to the Changed event of script.Parent.CurrencyToCollect.
2 Likes

Sorry, this is my second Post here. Where should I post this instead. (I just read other Tutorials, there as short as mine is)

Wow! Please give constructive Feedback. With this I can exactly do: nothing. Sorry.

Hey, thank you for your good Critique.

I just rewrote the post a bit. Thank you!

I know, what you mean. But this code is only an Extra Feature of Zed’s Tycoon Kit, so you don’t need to change the Code.

I also thought about this. But when I tested this, it caused extremely lag. (Imagine having 600 Parts dropping in a Part Collector in one sec.) You can change the cooldown of course.
Thank you for your feedback.