Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a currency script that adds the currency when a player touches a part?

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.

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)

2 comments

0

Thanks! That works nicely!

0

no problem! I'm here to help

This discussion is preserved as it was. New answers, comments, and votes are closed.