Forja

Roblox coin pickup script

Coins to collect: touch one to add it to your stat, and it comes back after a few seconds. One script runs every coin in the folder.

Where it goes

  1. 1It adds to a stat called Coins: add the leaderboard script too, so players have one.
  2. 2Add a Folder to Workspace and name it Coins. Put your coin Parts in it, with Anchored on and CanCollide off.
  3. 3In the Explorer, hover over ServerScriptService, press +, choose Script and paste this in.
CoinPickup · a Script in ServerScriptService
-- From forja.us/tools/roblox-scripts/coin-pickup-- Touch a coin to collect it. It comes back after a few seconds.local Players = game:GetService("Players")local VALUE = 1local BACK_AFTER_SECONDS = 10local coins = workspace:WaitForChild("Coins")local function setUpCoin(coin)	local taken = false	coin.Touched:Connect(function(hit)		if taken then			return		end		local character = hit:FindFirstAncestorOfClass("Model")		local player = character and Players:GetPlayerFromCharacter(character)		local leaderstats = player and player:FindFirstChild("leaderstats")		local stat = leaderstats and leaderstats:FindFirstChild("Coins")		if not stat then			return		end		taken = true		stat.Value += VALUE		coin.Transparency = 1		task.wait(BACK_AFTER_SECONDS)		coin.Transparency = 0		taken = false	end)endfor _, coin in coins:GetChildren() do	if coin:IsA("BasePart") then		setUpCoin(coin)	endend

How it works

  • The loop gives each coin its own Touched, so they don't need a script each.
  • taken stops one coin counting twice, because touching can fire several times at once.
  • It runs on the server, so players can't give themselves coins from their own device.

Make it yours

Worth more
Change VALUE.
Gone for good
Replace the lines after stat.Value += VALUE with coin:Destroy().
Want something more? The script generator can write it: “Coins that spin, play a sound when collected, and come back after 10 seconds”

Maps to try it on: simulator and tycoon maps

Start from a finished map, and your scripts have a game to run in.

More free Roblox scripts