SkidScripts

Code to make a "coin collecting" game for roblox

Nov 29th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. information about the script : https://controlc.com/6b4dc61c
  2. --------------------------------------------------------------------------------------------
  3. -- Variables
  4. local coinTemplate = game.Workspace.CoinTemplate -- Replace 'CoinTemplate' with the name of your coin model in Roblox
  5. local spawnArea = game.Workspace.SpawnArea -- Replace 'SpawnArea' with the name of the area where coins should spawn
  6. local spawnInterval = 5 -- Time interval between coin spawns (in seconds)
  7. local maxCoins = 10 -- Maximum number of coins in the game
  8. local collectedCoins = 0 -- Player's collected coins
  9.  
  10. -- Function to spawn coins
  11. local function spawnCoin()
  12.     local randomX = math.random(spawnArea.Position.X - spawnArea.Size.X / 2, spawnArea.Position.X + spawnArea.Size.X / 2)
  13.     local randomZ = math.random(spawnArea.Position.Z - spawnArea.Size.Z / 2, spawnArea.Position.Z + spawnArea.Size.Z / 2)
  14.     local coinClone = coinTemplate:Clone()
  15.     coinClone.Position = Vector3.new(randomX, spawnArea.Position.Y + 5, randomZ)
  16.     coinClone.Parent = game.Workspace
  17.     coinClone.Touched:Connect(function(hit)
  18.         if hit.Parent:FindFirstChild("Humanoid") then
  19.             coinClone:Destroy()
  20.             collectedCoins = collectedCoins + 1
  21.             print("Collected Coins: " .. collectedCoins)
  22.         end
  23.     end)
  24. end
  25.  
  26. -- Function to periodically spawn coins
  27. local function startCoinSpawning()
  28.     while true do
  29.         wait(spawnInterval)
  30.         if collectedCoins < maxCoins then
  31.             spawnCoin()
  32.         else
  33.             print("Max coins collected!")
  34.             break
  35.         end
  36.     end
  37. end
  38.  
  39. -- Start spawning coins
  40. startCoinSpawning()
Add Comment
Please, Sign In to add comment