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

How do i make my inventory save when leaving and rejoining?

Asked by 3 years ago

I got an inventory in which your hotbar items are displayed and you can equip those through there. Now i need to get a script in which i can make sure the player keeps that inventory when he/she rejoins. I got a script for Wins & Coins which are working right now. I dont understand how to save inventory slots tho. I used intvalues and the leaderstat folder for coins & wins. Following is the script for the inventory:

local player = game.Players.LocalPlayer
local character = player.Character
local items = {}
local buttons = {}
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false) -- Makes the original backpack gui invisible

function search(location)
    for i,v in pairs(location:GetChildren()) do -- Find all item in a specific location
        if v:isA("Tool") then -- If the item found is a "Tool"
            table.insert(items,v) -- We're going to put all the tools found in a table.
        end
    end
end

function refresh()
    for i,v in pairs(buttons) do -- Finds all items in the table
        v:Destroy() -- Destroy 'em all
    end
    for i,v in pairs(items) do -- Finds all items in the table
        local button = script.Sample:Clone() -- clones the sample button inside the localscript
        button.Name = v.Name -- sets the cloned button's name to the name of the item
        button.LayoutOrder = i
        button.Parent = script.Parent.Handler -- Sets the parent of the cloned button to the handler
        button.Image = v.TextureId -- Sets the image of the button to the texture id of the tool
        table.insert(buttons,button) -- Inserts the button to our table "buttons"
        button.MouseButton1Click:connect(function()
            if script.Parent.Handler.Selected.Value == nil or script.Parent.Handler.Selected.Value ~= v then -- Checks if the selected value is nothing or if the selected value is not the button
                script.Parent.Frame.ItemName.Text = v.Name -- Sets the TextLabel's Text to the name of the tool/button
                script.Parent.Frame.ImageLabel.Image = v.TextureId -- Sets the image label's image to the texture id of the tool
                script.Parent.Handler.Selected.Value = v
                if script.Parent.Handler.Selected.Value ~= script.Parent.Handler.Equipped.Value then --if the selected value is not the same as the equipped value then
                    script.Parent.Handler.Location.Value = v.Parent -- Sets the value of our location to the parent of the tool whether it is in the backpack or in the character
                    script.Parent.Frame.Equip.Text = "Equip" -- Self explanatory
                elseif script.Parent.Handler.Selected.Value == script.Parent.Handler.Equipped.Value then -- If the selected value is the same as the equipped value then...
                    script.Parent.Handler.Location.Value = v.Parent
                    script.Parent.Frame.Equip.Text = "Unequip"
                end
            end
        end)
    end
end

function backpackRefresh()
    items = {}
    search(character)
    search(player.Backpack)
    refresh()
end

backpackRefresh()

player.Backpack.ChildAdded:connect(backpackRefresh)
player.Backpack.ChildRemoved:connect(backpackRefresh)

character.ChildAdded:connect(backpackRefresh)
character.ChildRemoved:connect(backpackRefresh)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

This is the link to download the lua file:

https://www.mediafire.com/file/sbqn5dohrc89vbe/backpack+save.lua/file

0
@KidMudasir17 could you post it in Lua cause it is glitched for me rn jorrelnootje 12 — 3y
0
@jorrelnootje I have edited it now KidMudasir7 15 — 3y
0
@KidMudasir17 Can you just use the answer this question tool and then input it as lua? jorrelnootje 12 — 3y
0
@jorrelnootje I don't understand KidMudasir7 15 — 3y
Ad

Answer this question