In my opinion, the best way to store data for players is by using DataStore.
You can learn more about that here: http://wiki.roblox.com/index.php?title=Data_store
I will put an example below. This is only for reference. You might be able to copy and paste my script, but you won't learn anything. I would recommend that you do some research and regard this as an example if you need help.
01 | local DataStore = game:GetService( "DataStoreService" ) |
02 | local GoldStore = DataStore:GetDataStore( "GoldStore" ) |
04 | game.Players.PlayerAdded:Connect( function (Player) |
05 | local Leaderboard = Instance.new( "Folder" ,Player) |
06 | local Gold = Instance.new( "IntValue" ,Leaderboard) |
07 | Leaderboard.Name = "leaderstats" |
09 | Gold.Value = GoldStore:GetAsync(Player.UserId) or 0 |
12 | Gold.Changed:Connect( function () |
13 | GoldStore:SetAsync(Player.UserId, Gold.Value) |
16 | game.Players.PlayerRemoving:Connect( function (Player) |
17 | local Gold = Player.leaderstats.Gold |
18 | GoldStore:SetAsync(Player.UserId, Gold.Value) |