|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|