RB-004
Roblox coin pickup script
A coin that adds to the player's leaderstats when touched, then comes back after a while.
- Script type
- Script
- Where it goes
- Inside the Coin Part
- Category
- Player data and money
For your own game in Roblox Studio. Not for use in other people's games.
The code
-- Coin pickup: gives coins and respawns after a delay.
-- Needs the Leaderstats (coins) script so player.leaderstats.Coins exists.
local COIN_VALUE = 1
local RESPAWN_TIME = 10 -- seconds before the coin comes back. Use 0 to remove it for good.
local Players = game:GetService("Players")
local coin = script.Parent
local collected = false
coin.Touched:Connect(function(hit)
if collected then
return
end
local player = Players:GetPlayerFromCharacter(hit.Parent)
if not player then
return
end
local leaderstats = player:FindFirstChild("leaderstats")
local coins = leaderstats and leaderstats:FindFirstChild("Coins")
if not coins then
return
end
collected = true
coins.Value += COIN_VALUE
-- Hide the coin.
coin.Transparency = 1
coin.CanTouch = false
if RESPAWN_TIME <= 0 then
coin:Destroy()
return
end
task.wait(RESPAWN_TIME)
coin.Transparency = 0
coin.CanTouch = true
collected = false
end)How to set it up
- Make sure the Leaderstats (coins) script is already in ServerScriptService.
- Insert a Part, make it a yellow cylinder or a flat disc, and set Anchored to true. Turn CanCollide off.
- Add a Script inside the Part and paste the code.
- Copy and paste the coin around the map. Play and collect them.
Change it
- The coin is given by the server, so players cannot make up their own coins.
- Change COIN_VALUE to 5 or 10 for a more valuable coin.
- If coins do not count, check the stat is called exactly Coins and the folder exactly leaderstats.
More in Player data and money
- Leaderstats (coins)
- Save data with DataStore
- Shop button (RemoteEvent)
- Game pass check
- Developer product handler
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.