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)

1 comment
KeyDown is deprecated