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

Updating a save when a item is removed? [DESPERATE FOR HELP]

Asked by 11 years ago

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

01game:GetService("Players").PlayerAdded:connect(function(Plr)
02    Plr.CharacterAdded:connect(function(Char)
03        Plr:WaitForDataReady()
04 
05        local last = {}
06        local lastposition = UDim2.new(0, 0, 0, 0)
07        for _, v in pairs(game:GetService("ReplicatedStorage").Buttons:GetChildren()) do
08            if Plr:LoadString(v.Name) == v.Name then
09                if (last) then
10                print(Plr:LoadString(v.Name))
11                cl = v:Clone()
12                cl.Parent = Plr.PlayerGui.Inventory.Frame.Items
13                cl.Position = UDim2.new(0, 14, 0, 0) + lastposition
14                Plr.PlayerGui.Inventory.NumberOfItems.Value = Plr.PlayerGui.Inventory.NumberOfItems.Value +1
15                end
View all 21 lines...

-- Save script

01local Players = game:GetService("Players"
02 
03Players.PlayerAdded:connect(function(Plr)
04    Plr.Backpack.ChildAdded:connect(function(Item)
05        if Plr.DataReady then
06            for _, v in pairs(Plr.PlayerGui.Inventory.Frame.Items:GetChildren()) do
07                if v ~= nil then
08                    Plr:SaveString(v.Name,v.Name)
09                end
10            end
11        end
12    end)
13end)
14 
15Players.PlayerRemoving:connect(function(Plr)
View all 23 lines...

-- These scripts are not finished yet btw, and thanks for any help :P

1 answer

Log in to vote
0
Answered by 11 years ago

Try to make it so there is a boolvalue inside the item. When the script finds it, if the boolvalue is true/false then it removes it. (The item's boolvalue turns true/false after used)

Ad

Answer this question