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 10 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

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

1 answer

Log in to vote
0
Answered by 10 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