Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

Please include the code which you are trying to use, so the community will be better-equipped to help you with your problem.

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

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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)

0
Thanks! That works nicely! xx_iamwierd 4 — 3y
0
no problem! I'm here to help TheKakYTArmy 125 — 3y
Ad

Answer this question