01 | local ds = game:GetService( "DataStoreService" ) |
02 | local player = game:GetService( "Players" ) |
03 | local rep = game:GetService( "ReplicatedStorage" ) |
04 | local statsf = rep:WaitForChild( "Stats" ) |
05 | local datastore = ds:GetDataStore( "Stats" ) |
06 | local function saveData(player) |
07 | local speed = statsf:WaitForChild(player.Name):WaitForChild( "Speed" ) |
08 | local strength = statsf:WaitForChild(player.Name):WaitForChild( "Strength" ) |
09 | local data = { |
10 | speed.Value, |
11 | strength.Value |
12 | } |
13 |
14 | local success, err = pcall ( function () |
15 | datastore:SetAsync(player.UserId, data) |
Also, if there is any way to improve upon this script, let me know! Thank you
I think you are trying to save a table. Try to do this on line 14 to 16:
1 | local success, err = pcall ( function () |
2 | datastore:SetAsync(player.UserId.. " speed" , data [ 1 ] |
3 | datastore:SetAsync(player.UserId.. " strength" , data [ 2 ] |
4 | end ) |
Since you used the same key, and saved strength after speed, so your speed key will overlapped by the strength value (i think this is one of the problem, though), so you should consider use 2 different keys (your data will reset, sorry lol)