The reason why this isn't working is because you can't edit values in a local script, the solution to this would be to use remote events to fire a server script, which would require you to put a RemoteEvent in ReplicatedStorage. From there, you would need to edit your local script to look like this:
RS = game:GetService("ReplicatedStorage")
RE = RS:WaitForChild("RemoteEvent")
game.Players:WaitForChild(game.Players.LocalPlayer, 20)
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Button1Down:Connect(function()
RE:FireServer()
end)
Then, you would have to create a new script, which I would recommend to put in ServerScriptService, that looks like this.
RS = game:GetService("ReplicatedStorage")
RE = RS.RemoteEvent
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function()
RE.OnServerEvent:Connect(function(lPlayer)
if lPlayer == Player then
Player.leaderstats.Coins.Value = Player.leaderstats.Coins.Value + 1
print(Player.leaderstats.Coins.Value)
end
end)
end)
end)
Please let me know if you need any help!
Edit: For some people in the comments, it's true that it can change locally, but I made it public as it was leaderstats. I also fixed the script where I believe it will now work.
1 comment
Why is there a , 20 in the first line?