Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can i make a table to save string names, such as the tool save i am making?

Asked by 5 years ago

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

0
try actually watching videos about the concept instead of "copy paste this and uhhh it'll work" User#22604 1 — 5y
0
How can i save string values though? AdminAyush 10 — 5y
0
save it like other values User#23365 30 — 5y
View all comments (3 more)
0
Mkay, thanks AdminAyush 10 — 5y
0
Also - for tables, you may consider looking into JSON. SummerEquinox 643 — 5y
0
I'll take a look. AdminAyush 10 — 5y

Answer this question