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.

13 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.
3 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.

Not really something is worthy of a tutorial, created mine with 6 lines of code.

Can you imagine that some people just use a Tycoon Kit and don’t know anything about scripting and then they want an Auto Collect Script?

Your reply proves it: You can’t.

Btw, I‘ve seen some people asking for it in the Scripting Category so I created this.

Regardless: Your bumping this Topic for no reason that you can’t tell me privately or requires much attention.

So I have to create an new purchases model? My tycoon already has one.