Skip to content

Commit 9abec61

Browse files
authored
Update slot on tool change
Signed-off-by: GitHub <noreply@github.com>
1 parent 6f65849 commit 9abec61

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

src/Components/SlotButton.luau

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,27 @@ end
9595
function SlotButton.setTool(self: ClassType, tool: Tool | HopperBin?)
9696
self.tool = tool
9797

98-
if tool then
99-
self:setText(tool.Name)
100-
self:setIcon(tool.TextureId)
101-
if tool:IsA("Tool") then
102-
self:setTooltip(tool.ToolTip)
98+
local function onToolChange()
99+
if self.tool then
100+
self:setText(self.tool.Name)
101+
self:setIcon(self.tool.TextureId)
102+
if self.tool:IsA("Tool") then
103+
self:setTooltip(self.tool.ToolTip)
104+
end
105+
else
106+
self:setText("")
107+
self:setIcon("")
108+
self:setTooltip("")
103109
end
104-
else
105-
self:setText("")
106-
self:setIcon("")
107-
self:setTooltip("")
108110
end
111+
onToolChange()
112+
113+
local toolChangedConnection = tool.Changed:Connect(function(property)
114+
if property == "Name" or property == "TextureId" or property == "ToolTip" then
115+
onToolChange()
116+
end
117+
end)
118+
table.insert(self._connections, toolChangedConnection)
109119
end
110120

111121
function SlotButton.setText(self: ClassType, text: string)

0 commit comments

Comments
 (0)