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: How do I create a key in a DataStore?

Previous Thread :: Next Thread 
fireheart568 is not online. fireheart568
Joined: 04 Jan 2009
Total Posts: 1285
01 Apr 2014 07:37 PM
So I'm learning about DataStores, and I've made this code:

local FunStatistics = game:GetService("DataStoreService"):GetDataStore("FunStatistics")

local key = "ServersStarted"

FunStatistics:UpdateAsync(key, function(oldValue) newValue = oldValue + 1; script.ServersStarted.Value = newValue return newValue; end)







I understand that :UpdateAsync() will return nil if the key supplied does not exist, so what do I put in to create the key if one is not found?
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
01 Apr 2014 07:40 PM
Check object browser in the studio for help with specific objects like this. It will tell you all you need. If you want you can search "Setting DataStore Values Roblox Wiki" on google. You should find what you need. If you need anymore help then reply what you need.
Report Abuse
fireheart568 is not online. fireheart568
Joined: 04 Jan 2009
Total Posts: 1285
01 Apr 2014 07:45 PM
@cody

Thanks, that was helpful. (April fools...)

Anyways, I was reading another post about a similar topic and I put some new stuff in the code

-------------NEW CODE-------------
local FunStatistics = game:GetService("DataStoreService"):GetDataStore("FunStatistics")

local key = "ServersStarted"

keyExists = FunStatistics:GetAsync(key)

if keyExists == nil then
FunStatistics:SetAsync("ServersStarted", 0)
end

FunStatistics:UpdateAsync(key, function(oldValue) newValue = oldValue + 1; script.ServersStarted.Value = newValue return newValue; end)
-------------CODE END-------------

But when I try to print out the value of 'ServersStarted' in the command line from a test server, a blank space is printed. Not a 'nil' or an actual '1' like I was expecting, but a space.

What's happening?
Report Abuse
fireheart568 is not online. fireheart568
Joined: 04 Jan 2009
Total Posts: 1285
01 Apr 2014 07:46 PM
JUST KIDDING, IT WORKS!!!

I tested it wrong. It's working now. Thanks for indirectly helping me, other post!
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
02 Apr 2014 06:59 AM
The answer was given to you. It is simply put, If you don't know what method returns what then why are you coding? By memory?

Oh hey guys gotta remember that :WaitForChild() wait for the child. (but doesn't know that it returns the child too)
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