I assume this is in a touched event?
Anyways, on lines 2 and 3 you are using GetPlayerFromCharacter(), but failing to provide the character argument. You are basically trying to get the player from the character of nothingness. Try this:
if game.Players:GetPlayerFromCharacter(hit.Parent) then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
plr:WaitForChild("Leaderstats"):WaitForChild("Points").Value = plr.Leaderstats.Points.Value + 1
end
I also used WaitForChild() in case Leaderstats is not fully loaded when the code runs.
Note that the leaderstats will probably not show up on the in-game leaderboard because you named it 'Leaderstats' instead of 'leaderstats'.
Also note that since PlayerAdded events don't fire in PlaySolo mode, there will likely not be any leaderstats if you're trying to test it in PlaySolo.
Because of the nature of Touched event, you may want to look into adding a debounce.
2 comments
Is the Leaderstats and points value in the character? Or just in the Player. Try moving the values in Player so it wont get messed up online.
How?