Leaderstats is not a valid member of Players?

Okay, so I’m pretty new to scripting, so don’t judge. So i’ve been having trouble with this script. I don’t know how to fix it. I put this inside of a local script in a tool

image

image

4 Likes

You need to get your local player, for example game.Players.LocalPlayer.leaderstats.strength
leaderstats.Value = leaderstats.Value + 1

3 Likes

The simple fix to this is that you are getting the variable, “leaderstats” incorrectly. If you put leaderstats inside of the player, then the simple fix to this is:

local leaderstats = game:GetService("Players").LocalPlayer.leaderstats.strength.Value

Also, when referring to a service such as players, make sure you do game:GetService(“Players”) instead of game.Players

8 Likes

Also use remote events, if your doing this on client, you would have to fire server. https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

3 Likes

Leaderstats is not a member of Players, it is a folder inside of the Player that you are referring to. You will need to get the specific player that is clicking their mouse and go to their respective Player object.

Also, if you use a LocalScript it is a client sided change and will not show up on the server, so if you would like to do something like this you will need to change the leaderstats value using a ServerScript event and fire that event using a LocalScript. @dev_ity has kindly provided information on how to use RemoteEvents.

Little tip: the PlayerMouse is automatically passed to the Tool in the Equipped event, so you do not need to use GetMouse. In addition, Activated also works for this case.

You’ve also got some conflicting declarations and bad code going on there. The tool should only be handling player input in the case of needing to increment data.

Basic codebase:

Tool.Equipped:Connect(function (mouse)
    mouse.Button1Down:Connect(function ()
        Remote:FireServer()
    end)
end)

The server can then run conditional checks and act as necessary to add to a player’s stats.