Existence_YT

[RobloxStudioProjects] CustomHotbar - HB_Client 2

May 9th, 2020
3,720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.83 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2.  
  3. local UI = script.Parent
  4. local MainFrame = UI.MainFrame
  5. local StrNum = {["One"] = "1", ["Two"] = "2", ["Three"] = "3", ["Four"] = "4", ["Five"] = "5", ["Six"] = "6", ["Seven"] = "7", ["Eight"] = "8", ["Nine"] = "9"}
  6. local tools = {}
  7.  
  8. game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
  9.  
  10. local SelectedSlot = 0
  11. function hotbarKey(Slot)
  12.     for i, v in pairs(MainFrame:GetChildren()) do if v.ClassName == "ImageButton" then v.SlotName.TextColor3 = Color3.fromRGB(255,255,255) v.bg.ImageColor3 = Color3.fromRGB(46, 46, 46) v.ToolName.TextColor3 = Color3.fromRGB(255, 255, 255) end end
  13.     for i, v in pairs(plr.Character:GetChildren()) do if v:IsA("Tool") then v.Parent = plr.Backpack end end
  14.     for i, v in pairs(tools) do
  15.         if not v:FindFirstChild("SlotName") then return end
  16.         if v.SlotName.Value == Slot.Name then
  17.             v.Parent = plr.Character
  18.         end
  19.     end
  20.     SelectedSlot = tonumber(Slot.SlotName.Text)
  21.     Slot.SlotName.TextColor3 = Color3.fromRGB(0, 170, 255)
  22.     Slot.bg.ImageColor3 = Color3.fromRGB(255, 255, 255)
  23.     Slot.ToolName.TextColor3 = Color3.fromRGB(46, 46, 46)
  24. end
  25. function ConvKeyCode(KeyCode)
  26.     for i, v in pairs(StrNum) do
  27.         if KeyCode == Enum.KeyCode[i] then
  28.             if MainFrame:FindFirstChild("Slot"..v) then
  29.                 hotbarKey(MainFrame["Slot"..v])
  30.             else
  31.                 print("Slot"..v, false)
  32.             end
  33.         end
  34.     end
  35. end
  36.  
  37. plr.Backpack.ChildAdded:Connect(function(newChild)
  38.     tools = {}
  39.     for i, v in pairs(plr.Backpack:GetChildren()) do
  40.         if v:IsA("Tool") then
  41.             table.insert(tools, v)
  42.             if not v:FindFirstChild("SlotName") then return end
  43.             if MainFrame:FindFirstChild(v.SlotName.Value) then
  44.                 MainFrame:FindFirstChild(v.SlotName.Value).ToolName.Text = v.Name
  45.             end
  46.         end
  47.     end
  48. end)
  49.  
  50. game:GetService("UserInputService").InputBegan:Connect(function(key)
  51.     ConvKeyCode(key.KeyCode)
  52. end)
Advertisement
Add Comment
Please, Sign In to add comment