I know how to use data store but, here I am trying out something new that I have not done before. I want to give the player a wooden sword if they have nothing in their data store. Also I can't load in the data store.
local swordsFolder = script.Parent
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("ToolStore")
local Ss = game:GetService("ServerStorage")
game.Players.PlayerAdded:Connect(function(plr)
local char = plr.Character or plr.CharacterAdded:Wait()
local inv = Instance.new("Folder",plr)
inv.Name = "Inventory"
local data
local s, e = pcall(function()
data = DS:GetAsync(plr.UserId.."-Tools")
end)
if s then
if data == nil then
local clone = swordsFolder.WoodenSword:Clone()
clone.Parent = plr:WaitForChild("BackPack")
end
local invTable = {}
table.insert(invTable,data)
print(plr.Name.." - Tool store successful!")
else
warn(e)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local invTable = {}
for i,v in pairs(plr.Inventory:GetChildren()) do
table.insert(invTable,#invTable,v)
end
local s, e = pcall(function()
DS:SetAsync(plr.UserId.."-Tools",invTable)
end)
if s then
print(plr.Name.." - Tool data store successful!")
else
warn(e)
end
end)
Thanks for the help. It would be very useful if you found out what the problem is and how I can get over it.
Also, the output has no error in case you were going to ask.
