How to create an auto cash giver

Introduction
Hey there! I’m zDomivs and this is my first tutorial!

In the end of this tutorial you will be able to:

  • Create a currency
  • Create a script that gives all players a certain amount of currency every x seconds

This is a very simple script that will take you about 2-3 minutes to make.

This script was inspired by Developer School Tutorials

Step 1
Create a script inside ServerScriptService and call it “Leaderboard”
snip1

Step 2
Write the following code inside the “Leaderboard” script.

Step 3
Create another script inside “ServerScriptService” and call it “CashGiver” (or any other name you want)

snip3

Step 4
Write the following code inside the “CashGiver” script.

Conclusion
Thank you for reading and I hope this helped. Feel free to ask any questions or give any feedback on about this tutorial. Please let me know down below how good this tutorial was.

Have a nice day! :upside_down_face:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

0 voters

4 Likes

Nice tutorial.

Maybe next time use code blocks for scripts rather than an image, or use pastebin or something.

1 Like

I think this is a little too short and niche for this category, since it won’t be applicable to everyone’s use case. There are also existing resources for doing this. It’s not significant and doesn’t hold much utility to developers, so I can’t see it being very useful. Sorry.

Additionally, there are some practice issues with the code.

  • Please use GetService instead of directly accessing Players. You’ll want to use the canonical way to get services and be consistent with your other code, as not all services can be accessed through direct indexing.

  • The and v condition of the if statement in the CashGiver script is not necessary. GetPlayers returns a list of valid players in the Players service - in that instant that you’re working with the table, you aren’t going to have a gapless array.

  • Please don’t use while wait.

  • Please use ipairs over pairs. GetPlayers returns an array, not a dictionary. pairs is for working with dictionaries or otherwise where your keys are arbitrary or non-numerically contiguous.

  • These could all be in the same script provided you use coroutine/whatever implementation for pushing the per-minute giver into its own thread.

  • For any added signal, you’ll also want to run the function on any potentially existing members just in case your code yields and doesn’t connect the function in time.

local function playerAdded(player)
end

Players.PlayerAdded:Connect(playerAdded)
for _, player in ipairs(Players:GetPlayers()) do
    playerAdded(player)
end
5 Likes