Advertisement
OnFireRobloxScriptin

Simple Coin Spawner System

Aug 25th, 2024 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. --//NOTE: this will work with any coin, as long as coinamount exists and you decreased the coinamount counter when you collect your coin
  2.  
  3. --//Services
  4. local ReplicatedStorage = game:GetService("ReplicatedStorage") --Variable for Replicated Storage
  5.  
  6. --//Variables
  7. local coinamount = workspace.CoinAmount --Variable for IntAmount inside workspace
  8. local coin = ReplicatedStorage:WaitForChild("Coin") --Variable for your coin in the Replicated Storage
  9.  
  10. --//Functions
  11. local function spawnCoins() --New function to spawn coins
  12.     for count = 1, 20 do --Repeat 20 times (replace 20 with amount of coins you want to spawn)
  13.         local newcoin = coin:Clone() --Copy the coin
  14.         local randomx = math.random(-118, 150) --Random X Value
  15.         local randomz = math.random(-163, 190) --Random Z Value
  16.         newcoin.Position = Vector3.new(randomx, 1.5, randomz) --Place new coin in random place
  17.         newcoin.Parent = workspace --Place coin inside the workspace
  18.         coinamount.Value += 1 --Increment IntValue inside workspace
  19.     end
  20. end
  21.  
  22. spawnCoins() --Spawn coins when the server first starts
  23.  
  24. coinamount.Changed:Connect(function() --When number of coins changes
  25.     if coinamount.Value <= 10 then --If total number of coins drops to 10 or below (replace 10 with amount of coins you want left in the world before spawning more)
  26.         spawnCoins() --Spawn coins
  27.     end
  28. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement