Hi, I am making a game and I want to make a currency system. I have created the handler in a normal script in the ServerScriptService but I have no idea how to make it so that when a player touched a part (coin in my case) it adds one value to the players leaderstats.
✓ ANSWER ACCEPTED
How to make a currency script that adds the currency when a player touches a part?
1 answer
✓ Accepted answer
so this is simple enough, you just need to add a value to the leaderstat. Hope this helps!
--put this code in the coin
amount = 1 --how much you get for touching it
function onTouched(part)
local humanoid = part.Parent:FindFirstChild("Humanoid")
if (humanoid~=nil) then
local touch = game.Players:FindFirstChild(humanoid.Parent.Name)
local leaderstats = touch:FindFirstChild("leaderstats")
local points = leaderstats:FindFirstChild("Points") -- change "Points" with you own currency
points.Value = points.Value + amount
end
script.Parent:Destroy() -- optional, I added this because I think you'll want to destroy the coin after touching it.
end
script.Parent.Touched:Connect(onTouched)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thanks! That works nicely!
no problem! I'm here to help