Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- information about the script : https://controlc.com/6b4dc61c
- --------------------------------------------------------------------------------------------
- -- Variables
- local coinTemplate = game.Workspace.CoinTemplate -- Replace 'CoinTemplate' with the name of your coin model in Roblox
- local spawnArea = game.Workspace.SpawnArea -- Replace 'SpawnArea' with the name of the area where coins should spawn
- local spawnInterval = 5 -- Time interval between coin spawns (in seconds)
- local maxCoins = 10 -- Maximum number of coins in the game
- local collectedCoins = 0 -- Player's collected coins
- -- Function to spawn coins
- local function spawnCoin()
- local randomX = math.random(spawnArea.Position.X - spawnArea.Size.X / 2, spawnArea.Position.X + spawnArea.Size.X / 2)
- local randomZ = math.random(spawnArea.Position.Z - spawnArea.Size.Z / 2, spawnArea.Position.Z + spawnArea.Size.Z / 2)
- local coinClone = coinTemplate:Clone()
- coinClone.Position = Vector3.new(randomX, spawnArea.Position.Y + 5, randomZ)
- coinClone.Parent = game.Workspace
- coinClone.Touched:Connect(function(hit)
- if hit.Parent:FindFirstChild("Humanoid") then
- coinClone:Destroy()
- collectedCoins = collectedCoins + 1
- print("Collected Coins: " .. collectedCoins)
- end
- end)
- end
- -- Function to periodically spawn coins
- local function startCoinSpawning()
- while true do
- wait(spawnInterval)
- if collectedCoins < maxCoins then
- spawnCoin()
- else
- print("Max coins collected!")
- break
- end
- end
- end
- -- Start spawning coins
- startCoinSpawning()
Add Comment
Please, Sign In to add comment