Problem with adding values on leader stats

Hello everyone,

So I am learning to script and the vidoe I am watching is talking about when you click a brick it will give u a point in the leader stats. I understand how it all works but getting a error. If anyone could help me that would be great.
First Script to create the leaderstats:

game.Players.PlayerAdded:Connect(function(plr)
	local Leaderstats = Instance.new("Folder", plr)
	Leaderstats.Name = "leaderstats"
	
	local points = Instance.new("IntValue", Leaderstats)
	points.Name = "Points"
	points.Value = 100
end)

Second script to add on the points:

game.Workspace.Clickpoint.ClickDetector.MouseClick:Connect(function()
	local leaderpoint = Players.leaderstats.Points
	leaderpoint.Value = leaderpoint.value + 5
	
end)
1 Like

The leaderstats is right but the second script isnt

I suggest adding a player in the parameter function so you can get the leaderstats and then add cash like this.

game.Workspace.Clickpoint.ClickDetector.MouseClick:Connect(function(player)
local leaderstats = player.leaderstats
local points = leaderstats.Points

points.Value = points.Value + 1

end)

Where did you define the players in the second script that might be the problem

You should not be modifying leaderstats on the client.

That’s just the solution if you want that script to run without an error I believe :man_shrugging:

Why does it say on here then to?

1 Like

For the final script it should be

game.Players.PlayerAdded:Connect(function(plr)
local Leaderstats = Instance.new(“Folder”, plr)
Leaderstats.Name = “leaderstats”

local points = Instance.new("IntValue", Leaderstats)
points.Name = "Points"
points.Value = 100

end)

game.Workspace.Clickpoint.ClickDetector.MouseClick:Connect(function(player)
local leaderpoint = player.leaderstats.Points
leaderpoint.Value = leaderpoint.value + 5

end)

That is the exact thing I did??

Nothing will change on the server if you modify leaderstats on the client.

1 Like

you didn’t define the player in the script

game.Workspace.Clickpoint.ClickDetector.MouseClick:Connect(function(player) --gets the player who clicked it

Sorry about that. Ig I was trying to write a reply and didn’t notice that. Ill delete my post so nobody uses that lol

I’m definitely not a master at doing leaderstats and datasaves :confused:

Wow I am soo stupid. Thanks lol.

It’s also probably worth noting that you did not capitalize the second “Value.”

game.Workspace.Clickpoint.ClickDetector.MouseClick:Connect(function()
	local leaderpoint = Players.leaderstats.Points
	leaderpoint.Value = leaderpoint.**v**alue + 5
	
end)