Changing Currency Values

Hi, I’m currently working on a game where you have a currency. I have already made the leaderstats and a datastore function, but I can’t figure out how to change a player’s currency value itself, for example, if a player were to step or click on a part, then their currency value would be added by 100. How would I be able to achieve this? I have already checked other sources but I couldn’t seem to find any for some reason.

(Sorry if I formatted this wrong or if I didn’t provide enough information, this is my first time posting on the developer forum)

2 Likes

You have to define the value i.e.: player.leaderstats.Coins. and then change it with .Value .

So it would look like this;

player.leaderstats.Coins.Value = 100

Exactly…

Also, you can add to the existing Value like this:

player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100

(for example)

If you want to make a system that gives the player cash every minute or so, you need to use while loop and add player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1

Hope it helps you!

If you want to make the player gain 100 coins when he touches a part, then you would do this

game.Workspace.part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then -- checks if a player touched the brick
    game:GetService("Players")[hit.Parent.Name].leaderstats.Coins.Value = game:GetService("Players")[hit.Parent.Name].leaderstats.Coins.Value + 100
   end
end)

You might also want to add debounces!

1 Like

Thanks! This helped me out a lot!