|
| 08 Jul 2015 02:54 PM |
I intend to use my data store script inside the universe feature (games are already linked). I ask not that you redirect me to another link, but that you help me find the problem personally by guiding me on how to make a successful datastore system. Thanks.
--Save [Different Script than Load] Script: 1 local DataStore = game:GetService("DataStoreService"):GetDataStore("Gear")
game.Players.PlayerAdded:connect(function(player)
local key = "player-"..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then gere = savedValues[1]
else local valuesToSave = (gere) DataStore:SetAsync(key, (gere)) end
end)
--load [script 2]:
local DataStore = game:GetService("DataStoreService"):GetDataStore("Gear")
game.Players.PlayerRemoving:connect(function(player)
local key = "player-"..player.userId
local valuesToSave = (player.StarterGear.gere) DataStore:SetAsync(key,valuesToSave)
end) |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2015 03:03 PM |
Think of datastore like this...
local DataStore = {
}
local AddKey = function(index, value) DataStore[index] = value end
The value is not player specific.
Meaning "player-1234" could have either 1 data stored or a table of data...
---
Also, you can't save instances... nor do you ever want to..
Check out my models(or maybe my libraries...) for a module that will allow you to serialize data to table form to later instantiate the abstract object to normal. |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2015 03:52 PM |
--[[I looked further into help and actually got a working script
The script prints the gears it finds, it locates and saves them aswell. The only problem is in line 13 and 14 where it says to clone into the player parts it doesn't actually clone them?
No errors print so I can't locate the source of fault on my own.
Could you look into it?--]]
local TaS = game:GetService("DataStoreService"):GetDataStore("ToolsAndStuff")
function GiveStuff(player) local key = "user_" .. player.userId local items = TaS:GetAsync(key) local itemstoget = {} if not items then items = "" end for founditem in string.gmatch(items,"%P+") do print(founditem) table.insert(itemstoget,founditem.Name) end for i = 1, #itemstoget do game.Lighting:FindFirstChild(itemstoget[i]):Clone().Parent=player.StarterGear game.Lighting:FindFirstChild(itemstoget[i]):Clone().Parent=player.Backpack end end
function SaveStuff(player) local key = "user_"..player.userId TaS:UpdateAsync(key,function(oldVal) local allitems= "" local stuff = player.StarterGear:GetChildren() for i = 1, #stuff do if stuff[i].ClassName=="Tool" then allitems = allitems ..stuff[i].Name.."," end end return allitems end) end
game.Players.PlayerAdded:connect(GiveStuff) game.Players.PlayerRemoving:connect(SaveStuff) |
|
|
| Report Abuse |
|
|
| |
|
|
| 08 Jul 2015 04:43 PM |
Whoops it wouldn't work cus I put .Name on accident
It works now |
|
|
| Report Abuse |
|
|