generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Data store not saving outside of leaderstats

Previous Thread :: Next Thread 
Jakoo56 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image