Well, here it is hope this helps.
First off, a server script can't access the LocalPlayer
object. Also that's not a good way to go about doing this.
I'm also adding DataStore
for you so it saves it! You're welcome! XD
So do this in a Server script
01 | local startingCashValue = 0 |
03 | local DataStore = game:GetService( "DataStoreService" ) |
04 | local ds 1 = DataStore:GetDataStore( "MoneyDataStore" ) |
05 | game.Players.PlayerAdded:connect( function (plr) |
07 | local leader = Instance.new( "Folder" ) |
09 | local cash = Instance.new( "IntValue" ) |
11 | leader.Name = "leaderstats" |
17 | cash.Value = ds 1 :GetAsync(player.UserId) or startingCashValue |
23 | game.Players.PlayerRemoving:connect( function (player) |
24 | print ( "Saving Data For " ..player.Name.. ".." ) |
25 | ds 1 :SetAsync(player.UserId, player.leaderstats.Points.Value) |
26 | print ( "Data For " ..player.Name.. " has been saved!" ) |