Player = game.Players:GetPlayers() Player.leaderstats[Currency].Value = Player.leaderstats[Currency].Value + 30
Yet That the code can anyone help me this make me so confusing for this whole day god damn it.
Is the player variable wrong ?
Btw the error message is
23:32:53.333 - Workspace.Grass.Script:80: attempt to index field 'leaderstats' (a nil value)
I'll assume you have the leaderstats already set up, but if you don't, I have attached a link at the bottom of this answer that will help you do that.
Player = game.Players:GetPlayers() Player.leaderstats[Currency].Value = Player.leaderstats[Currency].Value + 30
The problem here is that the variable "Player" is referring to a table of players, which is what :GetPlayers() returns. It then tries to search that table for a value "leaderstats," but does not find it. In order to change each player's stats, you'll have to loop through the table of players. Here is a solution that will add to each player's stat.
local Players = game.Players:GetPlayers() for i = 1, #Players do -- this will loop through each value(players) in Players Players[i].leaderstats[Currency].Value = Player[i].leaderstats[Currency].Value + 30 end
If you want to give stats to a specific player:
local Player = game.Players.PlayerNameHere Player.leaderstats[Currency].Value = Player.leaderstats[Currency].Value + 30
Here are some resources on loops and creating leaderstats: https://developer.roblox.com/articles/Roblox-Coding-Basics-Loops https://developer.roblox.com/articles/Leaderboards