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: how do i make it where the person keeps their inventory

Previous Thread :: Next Thread 
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 12:28 PM
like they buy a taco and then leave the game and come back they still have the taco


Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
19 Aug 2016 12:28 PM
DataStores.


( ͡• ◡ ͡•) -=[ RAP: 378,777 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 12:30 PM
how do i set up a datastore, i know what it is but how do i set it up


Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 12:39 PM
ok i found a script that should save the inventory of the player and it says this at the top

local datastorename = ""

what do i put there


Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 12:43 PM
please help


Report Abuse
WrightPhillips99 is not online. WrightPhillips99
Joined: 27 Jun 2015
Total Posts: 667
19 Aug 2016 12:43 PM
I'm pretty sure you can just put it in startergear maybe but you may need datastore like he said.
Report Abuse
WrightPhillips99 is not online. WrightPhillips99
Joined: 27 Jun 2015
Total Posts: 667
19 Aug 2016 12:44 PM
sorry I meant starterpack
Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 12:45 PM
it's for a store so i can't put them in starterpack but thanks for responding


Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 12:48 PM
durst can you please tell me how to do this because you seem to be knowledgeable about it


Report Abuse
ByDefault is not online. ByDefault
Joined: 25 Jul 2014
Total Posts: 3197
19 Aug 2016 12:55 PM
You'd set up a folder of tools in ServerStorage, then use this script

local data = game:GetService("DataStoreService"):GetDataStore("Tools")
local http = game:GetService("HttpService")
local tools = game.ServerStorage.Tools

game.Players.PlayerAdded:connect(function(player)
local pData = data:GetAsync(player.userId)
if pData then
pData = http:JSONDecode(pData)
for i,v in pairs(pData) do
local t = tools:FindFirstChild(v):Clone()
t.Parent = player.Backpack
end
end
end)

game.Players.PlayerRemoving:connect(function(player)
local pData = {}
for i,v in pairs(player.Backpack:GetChildren()) do
table.insert(pData,v.Name)
end
data:SetAsync(player.userId, http:JSONEncode(pData))
end)
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
19 Aug 2016 12:58 PM
I don't know the first thing about DataStores, sorry bud. I've not had the time to look into them yet. I know other things though.


( ͡• ◡ ͡•) -=[ RAP: 378,347 || DurstAuric; the narb of ROBLOX ]=- ( ͡• ◡ ͡•)
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
19 Aug 2016 01:05 PM
all right, here's what you do

save ONE TABLE that contains all necessary player data when they leave or every minute or so

for now, i'll help you with then they enter and leave

--first, we'll define the datastore

local DataStore = game:GetService("DataStoreService"):GetDataStore("s9iDataService")

--name it anything you want, I chose your name

--so now, we'll define when a player enters:

game.Players.PlayerAdded:connect(function(player)

--now, we'll check if they have pre-existing stats(meaning their stats have saved before)

--we'll define a key with the player's userId in case they change names.

local key = player.UserId.."'s Stats"

local stats = DataStore:GetAsync(key)

if stats== nil then --this would mean the player has never had their stats saved, we'll now create a dictionary with the default stats for someone who is new

local playerData = {
["Inventory"] = {} --the array is empty since the player has no inventory items yet
}

end

--now, if the stats are not nil, we'll take all the inventory and clone it into the player's backpack(all these strings should be in server storage)

for i,v in next,stats.Inventory do
game.ServerStorage[v]:Clone().Parent = player.Backpack
end
--we took all the inventory values that were saved and put them into the player's backpack


now, when the player leaves, here is what you do

game.Players.PlayerRemoving:connect(function(player)
for i,v in next,player.Backpack:GetChildren() do
--iterate through all backpack items(which are the inventory stats) and put them BACK into the dictionary
table.insert(playerData.Invetory, v)
--that's how you add the inventory values into the Inventory table
--now we have playerData that we can save, so we use SetAsync.
DataStore:SetAsync(key,playerData)
end
end)
end)--we can use key and playerData from the PlayerAdded part since we haven't closed the anonymous function yet.

hopefully this helps


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 01:05 PM
yes! thank you so much it worked! :)
thank you


Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 01:07 PM
there is an issue though, most likely (definitely) my problem, but the items duplicate themselves every time i join the game. so if i leave with one bloxy cola and come back, i have 2. leave again and come back, i have 3.
how do i fix this??


Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
19 Aug 2016 01:09 PM
set the table to nil before you save, it's just going to keep inserting new values onto pre-existing ones even if they are already there

when you save on leave just do this

p.Data = {}


THEN save

make sense?


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 01:12 PM
sorry, what'a table


Report Abuse
s9i is not online. s9i
Joined: 07 Mar 2011
Total Posts: 7686
19 Aug 2016 01:14 PM
ah nvm, seems to be working now, thanks


Report Abuse
Crimsonal is not online. Crimsonal
Joined: 23 Apr 2011
Total Posts: 1795
19 Aug 2016 01:15 PM
"sorry, what'a table"
Report Abuse
ByDefault is not online. ByDefault
Joined: 25 Jul 2014
Total Posts: 3197
19 Aug 2016 01:18 PM
@LordNarwhal

Why would you save it every minute, that's highly inefficient and would most likely error due to bandwidth limitations
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
19 Aug 2016 01:20 PM
"Why would you save it every minute, that's highly inefficient and would most likely error due to bandwidth limitations"

i'm pretty sure it wouldn't

1 request per minute when you have over 60 will do nothing

i also don't see the point in json encoding/decoding

seems unnecessary at best


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
ByDefault is not online. ByDefault
Joined: 25 Jul 2014
Total Posts: 3197
19 Aug 2016 01:26 PM
Encoding/Decoding helps save on data + you can save mixed style tables, whereas saving every minute is completely unnecessary
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
19 Aug 2016 01:27 PM
"Encoding/Decoding helps save on data + you can save mixed style tables, whereas saving every minute is completely unnecessary"

that seems like it's total unnecessary

i can do what your script does with less lines and the same efficiency without needing more work

saving every minute is just a precaution to make sure even if you use game.OnClose in case of crashes that it's still going to save


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
ByDefault is not online. ByDefault
Joined: 25 Jul 2014
Total Posts: 3197
19 Aug 2016 01:36 PM
Your code has tonnes of flaws, this works perfectly (my version)

Btw, your broken code is 25 lines, my working code is 22 lines

local data = game:GetService("DataStoreService"):GetDataStore("Tools")
local http = game:GetService("HttpService")
local tools = game.ServerStorage.Tools

game.Players.PlayerAdded:connect(function(player)
local pData = data:GetAsync(player.userId)
if pData then
pData = http:JSONDecode(pData)
for i,v in pairs(pData) do
local tool = tools:FindFirstChild(v):Clone()
tool.Parent = player.Backpack
end
end
end)

game.Players.PlayerRemoving:connect(function(player)
local pData = {}
for i,v in pairs(player.Backpack:GetChildren()) do
table.insert(pData,v.Name)
end
data:SetAsync(player.userId, http:JSONEncode(pData))
end)
Report Abuse
Lord_Narwhal is not online. Lord_Narwhal
Joined: 05 May 2012
Total Posts: 3242
19 Aug 2016 01:39 PM
i took time to explain how it works and make it simple for op to understand

i could have made it much shorter

and you're calling me out when you just pasted a script with no explanation as to how it works

i'm the only one actually trying to help here

and you're saying that a maximum of probably 15 requests being used out of let's say,100, in a 15 player server is inefficient every minute

that's not going to overload the request limit

there's nothing wrong with double checking if data saves every minute or so


Formerly xXTheRobotXx, add 13,349 posts
Report Abuse
ByDefault is not online. ByDefault
Joined: 25 Jul 2014
Total Posts: 3197
19 Aug 2016 01:42 PM
k, think what you want but in reality my code is just straight up better and more efficient lol
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