I can't Unequip tools, I'm sure I did it correct, any help?
Hi. Question for this Hotbar.
In line 119 and 100, it doesn't unequip the tools.
I tried searching on the internet for the method to unequip and it is exactly the same with no errors whatsoever.
Everything works fine such as equipping tools, the Hotbar UI, the uis part, and the events.
001 | game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false ) |
043 | local uis = game:GetService( 'UserInputService' ) |
045 | local plr = game.Players.LocalPlayer |
047 | local backpack = game.Players.LocalPlayer:WaitForChild( 'Backpack' ) |
049 | local frame = script.Parent |
051 | repeat wait() until plr.Character |
053 | local char = plr.Character |
056 | for i, v in pairs (backpack:GetChildren()) do |
062 | backpack.ChildAdded:Connect( function (tool) |
063 | for i, v in pairs (tools) do |
066 | frame [ i ] .Image = 'rbxassetid://' ..tool:WaitForChild( 'ID' ).Value |
075 | backpack.ChildRemoved:Connect( function (tool) |
076 | for i, v in pairs (tools) do |
078 | if char:FindFirstChild(tool) then |
091 | for i, v in pairs (frame:GetChildren()) do |
092 | if v:IsA( 'ImageButton' ) then |
093 | uis.InputBegan:Connect( function (input) |
094 | local n = tonumber (v.Name) |
095 | if input.KeyCode = = Enum.KeyCode [ numinwords [ n ] ] then |
097 | if tools [ tonumber (v.Name) ] ~ = 'None' then |
099 | char.Humanoid:UnequipTools() |
100 | if char:FindFirstChild(tools [ tonumber (v.Name) ] .Name) then |
101 | char.Humanoid:UnequipTools() |
105 | char.Humanoid:EquipTool(tools [ tonumber (v.Name) ] ) |
115 | for i, v in pairs (frame:GetChildren()) do |
116 | if v:IsA( 'ImageButton' ) then |
117 | v.MouseButton 1 Click:Connect( function () |
118 | if tools [ tonumber (v.Name) ] ~ = 'None' then |
119 | char.Humanoid:UnequipTools() |
120 | if char:FindFirstChild(tools [ tonumber (v.Name) ] .Name) then |
121 | char.Humanoid:UnequipTools() |
125 | char.Humanoid:EquipTool(tools [ tonumber (v.Name) ] ) |