Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ds2 = require(game:GetService("ServerScriptService").Modules.DataStore2)
- local itemModule = require(game:GetService("ServerScriptService").Modules.ItemModule)
- local toolsFolder = game.ReplicatedFirst.Tools
- local resourceFolder = game.ReplicatedFirst.Resources
- ds2.Combine("DATA", "Tools")
- --Saving System--
- game.Players.PlayerAdded:Connect(function(player)
- local Backpack = player.Backpack
- local Inventory = player.PlayerGui:WaitForChild("Inventory")
- local toolStore = ds2("tools_", player)
- local resourceStore = ds2("resources_", player)
- local tools = toolStore:Get()
- local resources = resourceStore:Get()
- print("Retrieving Saved Tools")
- if tools ~= nil then
- for i, toolSaved in pairs(tools) do
- if toolSaved ~= nil then
- itemModule.addItemtoInventory(player, toolSaved, "Tool", 1)
- end
- end
- for i, r in pairs(resources) do
- if r ~= nil then
- local resource = resourceFolder[tostring(r[1])]:Clone()
- resource.Info.Type.Value = r[2]
- resource.Info.Distance.Value = r[3]
- resource.Info.FireRate.Value = r[4]
- resource.Info.Image.Value = r[5]
- resource.Parent = player.Backpack
- itemModule.addItemtoInventory(player, resource, "Tool", 1)
- end
- end
- end
- player.CharacterRemoving:Connect(function(character)
- character.Humanoid:UnequipTools()
- end)
- end)
- game.Players.PlayerRemoving:Connect(function(player)
- local toolStore = ds2("Tools", player)
- local toolsOwned = {}
- for i, tool in pairs(player.Backpack:GetChildren()) do
- local toolInfo = {}
- table.insert(toolInfo, tool.Name)
- for _, child in pairs(tool.Info:GetChildren()) do
- table.insert(toolInfo, child.Value)
- end
- table.insert(toolsOwned, toolInfo)
- print("saving " .. tool.Name)
- end
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
- local success, errormessage = pcall(function()
- toolStore:Set(toolsOwned)
- end)
- if success then print(player.Name .. "'s Inventory Data Saved") end
- if errormessage then warn(errormessage) end
- end)
- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Add Comment
Please, Sign In to add comment