Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Inventory data store not working how can i fix?

Hi guys im making a game and i want to save the inventory but it wont work theres no any errors on output

Script:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("myDataStore2")
local Players = game.Players
local ToolsFolder = game:GetService("ReplicatedStorage"):WaitForChild("Tools")

function PlayerAdded(plr)
	local key = plr.UserId;
	local Data;
	local stdout, stderror = pcall(function()
		Data = DataStore:GetAsync(key);
	end)
	if (Data ~= nil and type(Data) == "table") then
		for i,v in next,Data do
			if(ToolsFolder:FindFirstChild(v)) then
				print(stdout, stderror)
				ToolsFolder[v]:Clone().Parent = plr.Backpack;
			end
		end
	end
	print(stdout, stderror)
end

function PlayerRemoving(plr)
	local Tools = {};
	local key = plr.UserId;
	for i,v in next,plr.Backpack:GetChildren() do
		if (v:IsA("Tool")) then
			table.insert(Tools,v.Name);
		end
		print("Error 30")
	end
	for i,v in next,plr.Character:GetChildren() do
		if(v:IsA("Tool")) then
			table.insert(Tools,v.Name)
		end
	end
	local stdout, stderror = pcall(function()
		DataStore:GetAsync(key.Tools)
	end)

end

Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)

game:BindToClose(function()
	for i,v in next,Players:GetChildren()do
		PlayerRemoving(v)
	end
end)

1 answer

Your probably trying to do it from studio. It only works on online.

EDIT LINE --------------------------------------------- EDIT LINE

Since I'm lazy I will tell you how to do it. First you need to put the folder to a string

local stringfolder = tostring(game.Workspace.FOLDER)

Now you need a table

local tablefolder = {}

After that insert stringfolder to tablefolder

table.insert(tablefolder, stringfolder)

2 comments

0

Nope dont work on online

0

Let me edit my comment Zypsoh

This discussion is preserved as it was. New answers, comments, and votes are closed.