How would I finish this DataStore load?
I'm having a bit of trouble understanding what I should do for loading the Values from the Datastore table to the actual IntValues in the players leaderstats.
I'm really new to Datastores so if you could please break it down for me I would really appreciate it!
01 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "PlayerStats2" ) |
03 | local getStats = Instance.new( "BindableFunction" ) |
04 | getStats.Name = "getStats" |
05 | getStats.Parent = script |
07 | function saveStats(player) |
08 | local statz = player:FindFirstChild( "leaderstats" ) |
09 | local stats = statz:GetChildren() |
12 | for i,v in pairs (stats) do |
13 | statsTab [ v.Name ] = v.Value |
16 | ds:SetAsync( tostring (player.UserId), statsTab) |
20 | function getStats(player) |
21 | return ds:GetAsync( tostring (player.UserId)) or { } |
26 | for i,v in pairs (game.Players:GetPlayers()) do |
32 | game.Players.PlayerRemoving:connect(saveStats) |
33 | getStats.OnInvoke = getStats |