if the player clicks a viewportframe’s button it fires an event, but the thing is that it doesn’t work.
the viewport is not instantly added in the gui, but I think this should still have a work around
local inventory = script.Parent
local Equip = game:WaitForChild("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("EquipItem")
for _, v in pairs(inventory:GetChildren()) do
if v:IsA("ViewportFrame") then
local name = v.Name
v:FindFirstChild("Button").MouseButton1Up:Connect(function()
print("equip")
Equip:FireServer(name)
end)
end
end
I’d recommend adding repeat wait() until inventory:FindFirstChildOfClass("ViewportFrame") at line 3 to make sure it’s loaded. If there are a specific number of children Inventory is guaranteed to have when loaded, you could make it repeat wait() until inventory:FindFirstChildOfClass("ViewportFrame") and #inventory:GetChildren() == goalNum