Hello,
I am currently making a inventory system, which includes having a hotbar.
Everytime something gets added to the inventory I fire an Event which the client listens to. Then to update the hotbar I remove all slots from the Frame and then proceed to readd them with the updated state.
It works like this:
for _, v in ipairs(self.Items:GetChildren()) do
if v:IsA("TextButton") then
if v.Name == _drawn then
continue
end
v:SetAttribute("New", true)
end
end
for uid, data in pairs(Data) do
local ItemData = ItemModule[tonumber(data.Id)]
if ItemData then
local NewSlot = self.SlotTemplate:Clone()
NewSlot.TextLabel.Text = ItemData.Slot
NewSlot.ImageLabel.Image = ItemData.Thumbnail
NewSlot.Name = uid
NewSlot.Visible = false
NewSlot.LayoutOrder = ItemData.Slot
NewSlot.UIAspectRatioConstraint.AspectRatio = ItemData.Slot == 1 and 2 or 1
NewSlot.Parent = self.Items
end
end
However, this makes it so that if I have equipped something, when updating the hotbar it loses the state and does it so the equipped slot is not active anymore.
(I am not unequipping it myself)
https://medal.tv/games/roblox-studio/clips/x2tbOmlw0DkCD/d1337kheCzPz?invite=cr-MSwyMmcsMjE1Mzk4OTcs
How would I do so that the hotbar doesn’t lose state whenever I shoot or pick up an item from the ground.