|
| 10 Jan 2017 07:35 AM |
Hi, how do i make a script check the datastore of a player. for example in the datastore for a player there is a value which is 0. Then i want a script to check if that value is 0. To make the datastore for each player i used the code from the wiki tutorial, and i only got this far to make the script check. part is the brick that touches the parent of the script.
local key = "user_"..game.Players:GetPlayerFromCharacter(part.Parent).userId DataStore:GetAsync(key, function() end) |
|
|
| Report Abuse |
|
|
| |
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 10 Jan 2017 07:48 AM |
GetAsync iirc only has one argument, which is the key. so you'd say
local key = "user_"..game.Players:GetPlayerFromCharacter(part.Parent).userId local data = DataStore:GetAsync(key)
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 10 Jan 2017 07:48 AM |
2 minute bumps in the scripters subforum?
r u insane
|
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 07:51 AM |
| alright, but how do i check for a value in the data store? |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 10 Jan 2017 07:51 AM |
Well, what are you saying to that key in the first place? An array? One value?
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
| |
|
|
| 10 Jan 2017 07:54 AM |
the data is an array. i took this from my code: {planet1 = 0, escape1 = 0, escape2 = 0}
how would i for example wanna check if planet1 is higher than 0? |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 10 Jan 2017 07:56 AM |
That's a dictionary. You'd just say: print(data.planet1,data.escape1,data.escape2)
|
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 07:58 AM |
so i could just do
if data.planet1 == 0 then end |
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 08:00 AM |
no wait i still dont get it. would this work?
if DataStore:GetAsync(key).planet1 == 0 then end |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 10 Jan 2017 08:02 AM |
if data.planet1 > 0 then --stuff end
would check if planet1 in the datastore of the player is higher than 0, assuming you have declared data |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 10 Jan 2017 08:02 AM |
leTable = { ["Thing1"] = 0, ["Thing2"] = 0, ["Thing3"] = 0, }
print(leTable.Thing1) >0
|
|
|
| Report Abuse |
|
|
|
| 10 Jan 2017 08:04 AM |
| okay guys theres one more thing i dont understand. what is data? because i didnt declare that.. is data DataStore:GetAsync(key)? |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 10 Jan 2017 08:07 AM |
When we used the word "data" we're just using it as an arbitrary variable so that we don't have to use :GetAsync() over and over again. You can only use :GetAsync like 60+5*game.Players.NumPlayers times per minute
data = ds:GetAsync(key) could be any variable name apple = ds:GetAsync(key) pear_fruit = ds:GetAsync(key)
|
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 10 Jan 2017 08:07 AM |
Like soybeen showed you:
" local key = "user_"..game.Players:GetPlayerFromCharacter(part.Parent).userId local data = DataStore:GetAsync(key) " |
|
|
| Report Abuse |
|
|
| |
|