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

How can I refresh my custom inventory gui?

Asked by 6 years ago

How could I make my custom inventory GUI refresh its items whenever you pick up an item? I've tried using functions and running parts of the script again. However, that only duplicates the items instead of adding the item I picked up. I am unsure of how to do this. Help would be appreciated.

local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
    character = player.CharacterAdded:wait()
end

local StoredItems = {}
local Source = script.Parent.Background.InventoryBack
local Button = game.ReplicatedStorage.Replicated.Slot:Clone()


for i, v in pairs(player.PlayerGui.Items:GetChildren()) do
        table.insert(StoredItems, v)

end

for i = 1,#StoredItems do
            Button = game.ReplicatedStorage.Replicated.Slot:Clone()
            Button.Name = (StoredItems[i]).Name
            Button.Image = (StoredItems[i]).Img.Image
            Button.Parent = Source.Inventory
            Button.MouseButton1Click:Connect(function()
    if not Source.Inventory.Selected.Value or not StoredItems[Source.Inventory.Selected.Value] then
        script.Parent.Background.Equipment.ItemName.Text = (StoredItems[i]).Name
        script.Parent.Background.Equipment.ItemImage.Image = (StoredItems[i]).Img.Image
        script.Parent.Background.Equipment.ItemDescription.Text = (StoredItems[i]).Description.Value
        Source.Inventory.Selected.Value = (StoredItems[i])
        if Source.Inventory.Selected.Value ~= Source.Inventory.Equipped.Value then
            Source.Inventory.Location.Value = (StoredItems[i]).Parent
            script.Parent.Background.Equipment.Equip.Text = "Equip"
        elseif Source.Inventory.Selected.Value == Source.Inventory.Equipped.Value then
            Source.Inventory.Location.Value = (StoredItems[i]).Parent
            script.Parent.Equipment.Equip.Text = "Unequip"
        end
    end
end)
end



local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local frame = script.Parent.Background
local key = "e"

mouse.KeyDown:connect(function(k)
    if k:lower() == key then
        if frame.Visible then
            frame.Visible = false
        else
            frame.Visible = true
        end
    end
end)

0
KeyDown is deprecated User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

My suggestion would be to have it remove all the items currently in the gui (Not your inventory but the actual GUI) and then loop through the items and put them back in the GUI using a function which you call everytime a player drops/picks up an item.

Ad

Answer this question