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)
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
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)