Answered by
6 years ago Edited 6 years ago
You need to save when the player leaves the game too. I also added some things to the script that will help.
Try this:
02 | local DataStoreService = game:GetService( "DataStoreService" ) |
03 | local Players = game:GetService( "Players" ) |
06 | local DataStore = DataStoreService:GetDataStore( "NameHere" ) |
09 | local function Load(plr) |
11 | local leaderstats = Instance.new( "Folder" ) |
12 | leaderstats.Name = "leaderstats" |
13 | leaderstats.Parent = plr |
15 | local points = Instance.new( "IntValue" ) |
16 | points.Name = "Points" |
17 | points.Parent = leaderstats |
19 | local coins = Instance.new( "IntValue" ) |
21 | coins.Parent = leaderstats |
25 | local Key = "plr-" ..plr.UserId |
29 | SavedStats = DataStore:GetAsync(Key) |
34 | points.Value = SavedStats [ 1 ] |
35 | coins.Values = SavedStats [ 2 ] |
43 | DataStore:SetAsync(Key, Values) |
49 | local function Save(plr) |
50 | local Key = "plr-" ..plr.UserId |
53 | plr.leaderstats.Points.Value; |
54 | plr.leaderstats.Coins.Value |
58 | DataStore:SetAsync(Key, Values) |
62 | Players.PlayerAdded:Connect(Load) |
63 | Players.PlayerRemoving:Connect(Save) |
I know it may look intimidating since it has 63 lines but it's just an upgraded version to what you had. Also make sure you have datastore enabled for your place. If you don't you can enable it by going to your place and clicking on the tree dots. Next press configure this place. Click on Games. Then press the Allow this place to be updated using the Save Place API in your game.
checkbox.
Hope this helps!`