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 » Scripters
Home Search
 

Re: Data Store

Previous Thread :: Next Thread 
CrixusOdalisManiatus is not online. CrixusOdalisManiatus
Joined: 16 Jun 2011
Total Posts: 5987
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
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
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
CrixusOdalisManiatus is not online. CrixusOdalisManiatus
Joined: 16 Jun 2011
Total Posts: 5987
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
CrixusOdalisManiatus is not online. CrixusOdalisManiatus
Joined: 16 Jun 2011
Total Posts: 5987
08 Jul 2015 04:05 PM
bump
Report Abuse
CrixusOdalisManiatus is not online. CrixusOdalisManiatus
Joined: 16 Jun 2011
Total Posts: 5987
08 Jul 2015 04:43 PM
Whoops
it wouldn't work cus I put .Name on accident


It works now
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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