Thing is that my script saves the items in the inventory, but if the item is removed from the inventory it still loads it back (I kind of want consumable items)
-- Load script
game:GetService("Players").PlayerAdded:connect(function(Plr)
Plr.CharacterAdded:connect(function(Char)
Plr:WaitForDataReady()
local last = {}
local lastposition = UDim2.new(0, 0, 0, 0)
for _, v in pairs(game:GetService("ReplicatedStorage").Buttons:GetChildren()) do
if Plr:LoadString(v.Name) == v.Name then
if (last) then
print(Plr:LoadString(v.Name))
cl = v:Clone()
cl.Parent = Plr.PlayerGui.Inventory.Frame.Items
cl.Position = UDim2.new(0, 14, 0, 0) + lastposition
Plr.PlayerGui.Inventory.NumberOfItems.Value = Plr.PlayerGui.Inventory.NumberOfItems.Value +1
end
last = cl
lastposition = last.Position + UDim2.new(0, -14, 0, 50)
end
end
end)
end)
-- Save script
local Players = game:GetService("Players")
Players.PlayerAdded:connect(function(Plr)
Plr.Backpack.ChildAdded:connect(function(Item)
if Plr.DataReady then
for _, v in pairs(Plr.PlayerGui.Inventory.Frame.Items:GetChildren()) do
if v ~= nil then
Plr:SaveString(v.Name,v.Name)
end
end
end
end)
end)
Players.PlayerRemoving:connect(function(Plr)
if Plr.DataReady then
for _, v in pairs(Plr.PlayerGui.Inventory.Frame.Items:GetChildren()) do
if v ~= nil then
Plr:SaveString(v.Name,v.Name)
end
end
end
end)
-- These scripts are not finished yet btw, and thanks for any help :P
