im making a game where you receive tools after you defeat bosses. I need to make a tool saving script. But im not sure where to start. i know i need to save a table of tool names, then clone them into the players backpack, but im not sure how i should lay this out.

but i have tried some things.

local ds = game:GetService("DataStoreService"):GetDataStore("ToolSave")
game.Players.PlayerAdded:connect(function(plr)
 local key = "id-"..plr.userId
 pcall(function()
  local tools = ds:GetAsync(key)
  if tools then
   for i,v in pairs(tools) do
    local tool = game.ServerStorage.Items:FindFirstChild(v)
    if tool then
     tool:Clone().Parent = plr:WaitForChild("StarterGear")
    end
   end
  end
 end)
end)
game.Players.PlayerRemoving:connect(function(plr)
 local key = "id-"..plr.userId
 pcall(function()
  local toolsToSave = {}
  for i,v in pairs(plr.Backpack:GetChildren()) do
   if v then
    table.insert(toolsToSave,v.Name)
   end
  end
  ds:SetAsync(key,toolsToSave)
 end)
end)

this is from a video, that has showed up, im not sure how i can make this so it works. msot of the tutorials ive seen are outdated, please help!

--thanks, AdminAyush

7 comments

0

try actually watching videos about the concept instead of "copy paste this and uhhh it'll work"

0

How can i save string values though?

0

save it like other values

0

Mkay, thanks

0

Also - for tables, you may consider looking into JSON.

0

I'll take a look.