Answered by
6 years ago Edited 6 years ago
No you are using it correctly, However you shouldn't save your datastore under playeruserid alone. Add something to the end of player userid. This an old code of mine for a DataStore very similar to yours.
01 | local STOREDATAPLZ = { } |
02 | local storage = game:GetService( "DataStoreService" ):GetDataStore( "Test" ) |
04 | game.Players.PlayerAdded:connect( function (player) |
05 | local Stats = Instance.new( "StringValue" , player) |
06 | Stats.Name = "leaderstats" |
08 | local test = Instance.new( "NumberValue" , Stats) |
10 | test.Value = storage:GetAsync(player.userId.. "-test" ) or 0 |
11 | test.Changed:connect( function () |
12 | storage:SetAsync(player.userId.. "-test" , test.Value) |
13 | print ( "Stats saved :)" ) |
16 | game.Players.PlayerRemoving:connect( function (plr) |
17 | local testValue = plr.leaderstats.test |
18 | storage:SetAsync(plr.userId.. "-test" , testValue.Value) |
Notice how I added "-test" to the end of the player.userId so that the DataStoreService could find the specific number.
Edit: Also, the PlayerRemoving might not work on studio even if you have API Services activated, I remember when I wrote that script it did not, so I added the .Changed function