Answered by
7 years ago Edited 7 years ago
Solution
Since there is no differentiation in the key that you save your data to, it is going to keep being overwritten until the last index in the Model:GetChildren()
table.
I suggest you construct a dictionary, and save that :)
Tips
Saving everytime the data is changed is a bit overkill - Just save when the player leaves.
And personally, I like to simply store all player data as descendants of the player object - especially since the in-game leaderboard format requires this. But that's just my preference..
- Note:
connect
is deprecated, use Connect
!
Code
02 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "Stats" ) |
05 | game.Players.PlayerRemoving:Connect( function (p) |
08 | local Model = game.ServerStorage:FindFirstChild(p) |
09 | for i,v in pairs (Model:GetChildren()) do |
10 | data [ v.Name ] = v.Value |
12 | ds:UpdateAsync(player.UserId,data) |