So, I am making a script that when you touch a part, it gives you money. When I try to test it out, it says that players is a nil value.
Here's the code for the part:
script.Parent.Touched:connect(function() player = game:GetService("Players").LocalPlayer stats = players:findFirstChild("leaderstats") points = stats:findFirstChild("Points") points.Value = points.Value + 1 script.Parent:Destroy() print ("Coin completed") end)
Here's the leaderstats script:
game.Players.PlayerAdded:connect(function(player) stats = Instance.new("IntValue") stats.Parent = player stats.Name = "leaderstats" points = Instance.new("IntValue") points.Parent = stats points.Name = "Points" end)
Can someone please help me?

4 comments
is it a local script (code in the part)
obviously
I tried that, didn't work.
Research goes a long way. https://developer.roblox.com/api-reference/property/Players/LocalPlayer To quote the Dev Hub, "For Scripts running on the server, this property is nil."