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

Followed a tutorial on an item saving script, but it doesn't work how do I fix it?

Asked by 5 years ago

Hello, I followed this tutorial https://www.youtube.com/watch?v=PZp9nfuqPpQ on how to save items when players leave, but it won't work? Does anyone know why? Thanks. :)

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.Tools:FindFirstChild(v)
    if tool then
     tool:Clone().Parent = plr:WaitForChild("Backpack")
     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)
0
The Creator of the Video post an model with an updated Version in the comments: https://www.roblox.com/library/1006831332/Tool-DataStore RedstonecraftHD 25 — 5y
0
RedstonecraftHD Thank you so much, do you also have a link for the money datastore thingy? keketin 2 — 5y

Answer this question