I am making one Inventory system. It works but I want to save for every time the player join.
I am having 2 problems.
The tools is cloned into the backpack so when the player dies you have to select the tool again.
You have to select the tool every time you join.
I tried to do one IntValue system for save.
local player = game.Players.LocalPlayer
local RS = game:GetService("ReplicatedStorage")
local leaderstats = player:WaitForChild("toolLeaderstats") -- I am using IntValues for unlock the GUIs(works) but I want to use they for save the tools too.
local toolsRS = RS.Tools
local scrollFrameMelee = script.Parent.Parent.Meeles
--Loadout Values--
local loadout1 = leaderstats:WaitForChild("Loadout1")
local loadout2 = leaderstats:WaitForChild("Loadout2")
local loadout3 = leaderstats:WaitForChild("Loadout3")
--loadout buttons--
local loadoutButton1 = loadoutFrame.LoadButton1
local loadoutButton2 = loadoutFrame.LoadButton2
local loadoutButton3 = loadoutFrame.LoadButton3
--------Tool Buttons ------
local classic = scrollFrameMelee.ClassicSwordButton
local equip = script.Parent.ToolButton
local ToolNameText = script.Parent.ToolName
local ToolDescp = script.Parent.ToolDescription
local ToolImage = script.Parent.ToolImage
local selected = nil
local tool1Equipped = false
local tool1 = toolsRS.ClassicSword
equip.MouseButton1Click:Connect(function()
if selected == "classic" then
if tool1Equipped == false then
tool1Equipped = true
loadoutFrame.Visible = true
loadoutButton1.MouseButton1Click:Connect(function()
loadout1.Value = 1
loadoutFrame.Visible = false
end)
loadoutButton2.MouseButton1Click:Connect(function()
loadout2.Value = 1
loadoutFrame.Visible = false
end)
loadoutButton3.MouseButton1Click:Connect(function()
loadout3.Value = 1
loadoutFrame.Visible = false
end)
tool1:Clone().Parent = player.Backpack
equip.Text = "Unequip weapon"
equip.BackgroundColor3 = Color3.fromRGB(170, 0, 0)
else
tool1Equipped = false
equip.Text = "Equip weapon"
equip.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
player.Backpack:FindFirstChild("ClassicSword"):Destroy()
if loadout1.Value == 1 then
loadout1.Value = nil
end
if loadout2.Value == 1 then
loadout2.Value = nil
end
if loadout3.Value == 1 then
loadout3.Value = nil
end
end
end
end)
---trying to clone the tools when the player join.
game.Players.PlayerAdded:Connect(function()
----------------------------------------
print("s")
if loadout1.Value == 1 then
tool1Equipped = true
tool1:Clone().Parent = player.Backpack
elseif loadout1.Value == 2 then
tool2Equipped = true
----------------------------------------
if loadout2.Value == 1 then
tool1Equipped = true
tool1:Clone().Parent = player.Backpack
elseif loadout2.Value == 2 then
tool2Equipped = true
tool2:Clone().Parent = player.Backpack
end
end
end)
this is just one test I am making for see if I can save the tools.
Gif:
The values changes.
I am trying to make something like:
Max 3 slots for inside the backpack (I am still trying to work on it)
Clone tools in the backpack everytime the player join and clone everytime the character spawns. (Maybe one function I can use for it).
local limit = 3
for i,v in pairs(game.Players.LocalPlayer.LocalPlayer.Backpack:GetChildren()) do
if i >= limit + 1 then
v:Destroy()
end
end
For tool to respawn in player backpack after death:
Clone the objects to player.StarterPack as backpack will reset after player dies, if you clone to starter pack the objects will clone to backpack automatically
For tools saving
local dss = game:GetService("DataStoreService")
local dsfortools = dss:GetDataStore("ToolsSave")
game.Players.PlayerAdded:Connect(function(plr)
if dsfortools:GetAsync(plr.UserId) then
local tabletoload = dsfortools:GetAsync(plr.UserId)
for i,v in pairs(tabletoload) do
if replicatedstorage:FindFirstChild(v) then
local clone = replicatedstorage:FindFirstChild(v):Clone()
clone.Parent = plr.StarterPack
end
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local newtable = {}
for i,v in pairs(plr.Backpack:GetChildren()) do
table.insert(newtable,v.Name)
end
end)
So, you keep all your tools in replicated storage or a folder in replicated storage, you save the tool names when player is leaving and then when they join back, if they have their user id saved their table will load then, from the loaded table you clone tools and keep in starter pack for respawn for tools after player dies
Yes you can, I guess but thats how it respawns after player dies, and don’t save big data stores for tools, use name system using a table and save the table
One more question for the max slots in inventory I cant just do that because the gui will change I can do something like when the backpack limit is 3 this can say “Inventory is full”
You can but thats why too messed up and complicated, if you try the script I sent it worked many times for me and you can also try it, its just an 8 line script
If I turn off the ResetOnSpawn the gui will not reset but the tool will get deleted after death so I have to use one Remote event for clone to starterpack?
Clone the objects to player.StarterPack as backpack will reset after player dies, if you clone to starter pack the objects will clone to backpack automatically
This line, if you clone to starter pack when equiping, you don’t any script to respawn it in player backpack again
If anything is in StarterPack you don’t need to keep them in backpack, its like default starter pack which is in the explorer, anything there will go to backpack