AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 30 Jan 2015 04:35 PM |
This is a very basic data store script, since it's my first time trying. Here's what happens when leaving and joining:
datastore:SetAsync("Slot1", {Item=Player.PlayerGui.Inventory.Frame.Backpack.Slot1.Item.Value})
print(datastore:GetAsync("Slot1").Item)
Whenever I join, it prints blank or nil. But, when I just do this:
datastore:SetAsync("Slot1", {Item=5})
print(datastore:GetAsync("Slot1").Item)
It prints 5. The point is, why cant I just save like that? Is there an alternative way to do this? |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|
|
| 31 Jan 2015 07:40 AM |
| I don't know, but u might want to change value.Value to value and then use the Key.Value |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|
|
| 31 Jan 2015 07:45 AM |
try something like this
local ds = game:GetServive('DataStoreService'):GetDataStoreName('NameOfUrKey') ds:SetAsync('Key', value)
--then
theValue = ds:GetAsync('Key', value)
print(theValue.Value)
try this |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 07:51 AM |
| What is the purpose of key's? |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 08:24 AM |
here read this while I develop my Test Range with DataStores to Store 'Bullets Hit', 'Died', and 'Kills'...
http://wiki.roblox.com/index.php?title=Data_store |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 03:02 PM |
local key = "player_"..Player.userId
datastore:GetAsync(key, function() print(datastore:GetAsync("Slot1").Item)
datastore:SetAsync(key, function() datastore:SetAsync("Slot1", {Item=Player.PlayerGui.Inventory.Frame.Backpack.Slot1.Item.Value})
Nothing prints. Do I need to incorporate key into the very last line somehow? ^ |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 03:09 PM |
local ds = game:GetService('DataStoreService'):GetDataStoreName(Name) local key = "player_"..Player.userId print(ds:GetAsync(key)) ds:SetAsync(key, something.Value)
something like that... of course Roblox recommend to use the function to check stuff, but u dont always need it... |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 04:35 PM |
Everytime I use this to set data it runs
datastore:SetAsync(key, function(newValue)
return newValue
But if I use this it even go past the function line
datastore:GetAsync(key, function(oldValue)
return oldValue
why? |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 04:49 PM |
dunno... just use my Example... cos I need to sleep right now, am tired and cant think |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 05:36 PM |
I'm getting really frustrated because I can't figure out how to do this. This is in server script serivce.
game.Players.PlayerRemoving:connect(function(Player) local Backpack = Player.PlayerGui:WaitForChild("Inventory").Frame.Backpack local key = "player_" .. Player.userId --datastore:SetAsync(key, function(newValue) datastore:SetAsync(key, function(newValue) if Player.PlayerGui.Inventory.Frame.Backpack.Slot1.AmmoType.Value then local newValue = datastore:SetAsync(key, ("Slot1"){ -- ItemType=Player.PlayerGui.Inventory.Frame.Backpack.Slot1.ItemType.Value, Item=Player.PlayerGui.Inventory.Frame.Backpack.Slot1.Item.Value, -- Amount = Player.PlayerGui.Inventory.Frame.Backpack.Slot1.Amount.Value, -- MaxAmount = Player.PlayerGui.Inventory.Frame.Backpack.Slot1.MaxAmount.Value, -- AmmoType = Player.PlayerGui.Inventory.Frame.Backpack.Slot1.AmmoType.Value, }) end return newValue end) end) -- This loads up data ON JOIN. game.Players.PlayerAdded:connect(function(Player) local Backpack = Player.PlayerGui:WaitForChild("Inventory").Frame.Backpack local key = "player_" .. Player.userId local item = datastore:GetAsync(key,("Slot1").Item) print("key is "..key) print(item) end)
1. It prints the key 2. It just prints "Slot1" |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 05:47 PM |
| I needa go sleep, in the meanwhile just use my Script, if u dont know how, ask the people... |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 05:48 PM |
@Kap
Ye, that's why I posted that to see if anyone else could help |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 05:55 PM |
| no I mean ask in PM or watever |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
| |
|
| |
|
|
| 31 Jan 2015 06:24 PM |
The problem is the script is firing before the objects load. Try this:
datastore:SetAsync("Slot1", {Item=Player:WaitForChild("PlayerGui"):WaitForChild("Inventory"):WaitForChild("Frame"):WaitForChild("Backpack"):WaitForChild("Slot1"):WaitForChild("Item").Value}) |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 06:28 PM |
| I'll add that in and see what happens. |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 07:12 PM |
@warpsy
That's not the problem, but I'll keep testing around. |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 07:32 PM |
Here's what I got so far
if datastore:GetAsync(key, "Slot1") ~= nil then print'Its true' print(datastore:GetAsync(key, "Slot1")) if datastore:GetAsync(key, ("Slot1").Item) ~= nil then print'Item in slot1 is true' print(datastore:GetAsync(key, ("Slot1").Item)) end end
Output:
Its true Slot1 Item in slot1 is true Slot1
How come the last print, that prints Slot1.Item, wont print? That's pretty much how its done on the wiki: print(ds:GetAsync("foo").x) |
|
|
| Report Abuse |
|
|
|
| 31 Jan 2015 07:37 PM |
if datastore:GetAsync(key, "Slot1") ~= nil then print'Its true' print(datastore:GetAsync(key, "Slot1")) if datastore:GetAsync(key, ("Slot1").Item) ~= nil then print'Item in slot1 is true' print(datastore:GetAsync(key, ("Slot1").Item)) end end
I'm confused:
datastore:GetAsync(key, "Slot1") datastore:GetAsync(key, ("Slot1").Item)
Why are you passing GetAsync in 2 arguments? It only takes 1, the key in which a value is saved under. |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 31 Jan 2015 07:41 PM |
| Explain? This is all very new to me |
|
|
| Report Abuse |
|
|