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 » Scripting Helpers
Home Search
 

Re: Datastore with stats

Previous Thread :: Next Thread 
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
01 Jun 2014 10:16 PM
If I create some stats ...

local DS = game:GetService("DataStoreService"):GetOrderedDataStore("Wins")
local u = assert(LoadLibrary("RbxUtility"))
stats = {Tix = 0, Wins Tokens = 0, Wins = 0}

function PlayerAdded(p)

local strstats = u.EncodeJSON(stats)
local ls = Instance.new("IntValue", p)
ls.Name = "leaderstats"
-- what do I do to save those stats as IntValues under leaderstats?
strstats.Wins.Changed:connect(function(v)
DS:SetAsync(p.userId, v)
end)
end

-- connection line stuff
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Jun 2014 10:17 PM
for key, value in next, stats do
local stat = Instance.new("IntValue", ls);
stat.Name = key;
stat.Value = value;
end
Report Abuse
JimmyChance is not online. JimmyChance
Joined: 01 Nov 2009
Total Posts: 3681
01 Jun 2014 10:20 PM
Should I rid the JSON part? I just wanted to make a faster stat creation.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Jun 2014 10:21 PM
If you plan on saving this, you should convert it to a JSON when you save and back to a table after you load.
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 Jun 2014 10:26 PM
You can save tables to DataStore directly without converting





"Dont judge a user by what they're wearing"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Jun 2014 10:28 PM
Is it not less "space-consuming" if you store it as a string in JSON format?
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 Jun 2014 10:33 PM
It automatically converts to JSON anyways so idk. Its easier to code without converting tbh.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
01 Jun 2014 10:35 PM
Oh, it is? And when you load it, the value returned is automatically a table I'll assume? I don't know too much about datastore since I never actually need to save anything
Report Abuse
wazap is not online. wazap
Joined: 29 Jun 2007
Total Posts: 23234
01 Jun 2014 10:36 PM
Yup, its converted automatically




"Dont judge a user by what they're wearing"
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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