Jakoo56
|
  |
| Joined: 22 Nov 2015 |
| Total Posts: 4 |
|
|
| 22 Mar 2016 12:57 PM |
So i made a data store script (or rather took one and edited it a bit) and it seems like it doesnt want to save outside of leaderstats.
script:
local datastore = game:GetService("DataStoreService"):GetDataStore("PlayerStats")
game.Players.PlayerRemoving:connect(function(player) player:WaitForDataReady() -- make sure we aren't looking for leaderstats before they are created wait(2) -- just in case --local stats = player:FindFirstChild("leaderstats"):GetChildren() local stats3 = player:FindFirstChild("C1"):GetChildren()
--for i = 1, #stats do -- creates a loop for all the stats --print(stats[i].Name) --datastore:SetAsync(stats[i].Name, stats[i].Value) --end
for i = 1, #stats3 do -- creates a loop for all the stats print(stats3[i].Name) datastore:SetAsync(stats3[i].Name, stats3[i].Value) end end)
game.Players.PlayerAdded:connect(function(newplayer) newplayer:WaitForDataReady() wait(2) --local stats2 = newplayer:FindFirstChild("leaderstats"):GetChildren() local stats4 = newplayer:FindFirstChild("C1"):GetChildren() --for i = 1, #stats2 do --stats2[i].Value = datastore:GetAsync(stats2[i].Name) --end for i = 1, #stats4 do stats4[i].Value = datastore:GetAsync(stats4[i].Name) end end)
i put "--" over the parts that saves leaderstats just to see if it was working.
I want to save into "player.C1.X.Value" (X being a value name)
The C1 Values are already made in a "value creator" script.
this script is placed into "game.Workspace".
hope it's just one of my mistakes and it can be fixed! |
|
|
| Report Abuse |
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 22 Mar 2016 01:11 PM |
Here is an example of a working DataStore
local ds = game:GetService("DataStoreService"):GetDataStore("PlayerData")
game.Players.PlayerAdded:connect(function(player) local stats = Instance.new("IntValue",player) stats.Name = "leaderstats" local rating = Instance.new("IntValue",stats) rating.Name = "Rating" rating.Value = ds:GetAsync("Rating_"..player.UserId) or 1200 end)
game.Players.PlayerRemoving:connect(function(player) local stats = player:WaitForChild("leaderstats") local rating = stats:WaitForChild("Rating") ds:SetAsync("Rating_"..player.UserId, rating.Value) end) |
|
|
| Report Abuse |
|