Advertisement
w3vu2m81e912ce7m

my ui lib

Jun 21st, 2025 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.10 KB | None | 0 0
  1. local Library = {}
  2.  
  3. -- Services
  4. local UserInputService = game:GetService("UserInputService")
  5. local RunService = game:GetService("RunService")
  6. local CoreGui = game:GetService("CoreGui")
  7.  
  8. -- Main ScreenGui
  9. local screenGui = Instance.new("ScreenGui")
  10. screenGui.Name = "AdvancedUILibrary"
  11. screenGui.ResetOnSpawn = false
  12. screenGui.Parent = CoreGui
  13.  
  14. -- Main draggable frame
  15. local mainFrame = Instance.new("Frame")
  16. mainFrame.Name = "MainFrame"
  17. mainFrame.Size = UDim2.new(0, 300, 0, 400)
  18. mainFrame.Position = UDim2.new(0, 50, 0, 50)
  19. mainFrame.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
  20. mainFrame.BorderSizePixel = 0
  21. mainFrame.Parent = screenGui
  22. mainFrame.Active = true
  23. mainFrame.Draggable = true
  24.  
  25. -- UIListLayout container for controls inside mainFrame
  26. local contentHolder = Instance.new("Frame")
  27. contentHolder.Name = "ContentHolder"
  28. contentHolder.BackgroundTransparency = 1
  29. contentHolder.Size = UDim2.new(1, -20, 1, -40)
  30. contentHolder.Position = UDim2.new(0, 10, 0, 35)
  31. contentHolder.Parent = mainFrame
  32. contentHolder.ClipsDescendants = true
  33.  
  34. local layout = Instance.new("UIListLayout")
  35. layout.SortOrder = Enum.SortOrder.LayoutOrder
  36. layout.Padding = UDim.new(0, 8)
  37. layout.Parent = contentHolder
  38.  
  39. -- Title Label
  40. local titleLabel = Instance.new("TextLabel")
  41. titleLabel.Parent = mainFrame
  42. titleLabel.Text = "Advanced UI Library"
  43. titleLabel.Size = UDim2.new(1, 0, 0, 30)
  44. titleLabel.Position = UDim2.new(0, 0, 0, 0)
  45. titleLabel.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
  46. titleLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
  47. titleLabel.Font = Enum.Font.SourceSansBold
  48. titleLabel.TextSize = 22
  49. titleLabel.BorderSizePixel = 0
  50.  
  51. -- Helper to create labels for controls
  52. local function createLabel(text)
  53. local label = Instance.new("TextLabel")
  54. label.Size = UDim2.new(1, 0, 0, 20)
  55. label.BackgroundTransparency = 1
  56. label.TextColor3 = Color3.fromRGB(255, 255, 255)
  57. label.Font = Enum.Font.SourceSansSemibold
  58. label.TextSize = 18
  59. label.Text = text
  60. label.TextXAlignment = Enum.TextXAlignment.Left
  61. return label
  62. end
  63.  
  64. -- Toggle control
  65. function Library:CreateToggle(name, callback)
  66. local toggled = false
  67.  
  68. local frame = Instance.new("Frame")
  69. frame.Size = UDim2.new(1, 0, 0, 40)
  70. frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  71. frame.Parent = contentHolder
  72.  
  73. local label = createLabel(name)
  74. label.Size = UDim2.new(0.7, 0, 1, 0)
  75. label.Parent = frame
  76.  
  77. local button = Instance.new("TextButton")
  78. button.Size = UDim2.new(0.28, 0, 0.6, 0)
  79. button.Position = UDim2.new(0.72, 0, 0.2, 0)
  80. button.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
  81. button.TextColor3 = Color3.fromRGB(255, 255, 255)
  82. button.Font = Enum.Font.SourceSansBold
  83. button.TextSize = 18
  84. button.Text = "OFF"
  85. button.Parent = frame
  86.  
  87. button.MouseButton1Click:Connect(function()
  88. toggled = not toggled
  89. button.Text = toggled and "ON" or "OFF"
  90. button.BackgroundColor3 = toggled and Color3.fromRGB(0, 170, 0) or Color3.fromRGB(80, 80, 80)
  91. if callback then callback(toggled) end
  92. end)
  93.  
  94. return {
  95. Set = function(value)
  96. toggled = value
  97. button.Text = toggled and "ON" or "OFF"
  98. button.BackgroundColor3 = toggled and Color3.fromRGB(0, 170, 0) or Color3.fromRGB(80, 80, 80)
  99. if callback then callback(toggled) end
  100. end,
  101. Get = function() return toggled end
  102. }
  103. end
  104.  
  105. -- Input control (TextBox)
  106. function Library:CreateInput(name, defaultText, callback)
  107. local frame = Instance.new("Frame")
  108. frame.Size = UDim2.new(1, 0, 0, 40)
  109. frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  110. frame.Parent = contentHolder
  111.  
  112. local label = createLabel(name)
  113. label.Size = UDim2.new(0.35, 0, 1, 0)
  114. label.Parent = frame
  115.  
  116. local textbox = Instance.new("TextBox")
  117. textbox.Size = UDim2.new(0.6, 0, 0.7, 0)
  118. textbox.Position = UDim2.new(0.4, 0, 0.15, 0)
  119. textbox.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
  120. textbox.TextColor3 = Color3.fromRGB(255, 255, 255)
  121. textbox.Font = Enum.Font.SourceSans
  122. textbox.TextSize = 18
  123. textbox.Text = defaultText or ""
  124. textbox.ClearTextOnFocus = false
  125. textbox.Parent = frame
  126.  
  127. textbox.FocusLost:Connect(function(enterPressed)
  128. if enterPressed and callback then
  129. callback(textbox.Text)
  130. end
  131. end)
  132.  
  133. return {
  134. Set = function(value)
  135. textbox.Text = tostring(value)
  136. end,
  137. Get = function()
  138. return textbox.Text
  139. end
  140. }
  141. end
  142.  
  143. -- Slider control
  144. function Library:CreateSlider(name, min, max, defaultValue, callback)
  145. local sliderValue = defaultValue or min
  146.  
  147. local frame = Instance.new("Frame")
  148. frame.Size = UDim2.new(1, 0, 0, 50)
  149. frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  150. frame.Parent = contentHolder
  151.  
  152. local label = createLabel(name)
  153. label.Size = UDim2.new(1, 0, 0, 20)
  154. label.Parent = frame
  155.  
  156. local sliderBar = Instance.new("Frame")
  157. sliderBar.Size = UDim2.new(1, -40, 0, 10)
  158. sliderBar.Position = UDim2.new(0, 10, 0, 30)
  159. sliderBar.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
  160. sliderBar.Parent = frame
  161.  
  162. local sliderFill = Instance.new("Frame")
  163. sliderFill.Size = UDim2.new((sliderValue - min) / (max - min), 0, 1, 0)
  164. sliderFill.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
  165. sliderFill.Parent = sliderBar
  166.  
  167. local sliderBtn = Instance.new("TextButton")
  168. sliderBtn.Size = UDim2.new(0, 15, 1, 0)
  169. sliderBtn.Position = UDim2.new((sliderValue - min) / (max - min) - 0.05, 0, 0, 0)
  170. sliderBtn.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
  171. sliderBtn.Text = ""
  172. sliderBtn.Parent = sliderBar
  173. sliderBtn.AutoButtonColor = false
  174.  
  175. local dragging = false
  176.  
  177. local function updateSlider(x)
  178. local relativeX = math.clamp(x - sliderBar.AbsolutePosition.X, 0, sliderBar.AbsoluteSize.X)
  179. local value = min + ((relativeX / sliderBar.AbsoluteSize.X) * (max - min))
  180. sliderValue = math.floor(value * 100) / 100 -- round to 2 decimals
  181. sliderFill.Size = UDim2.new((sliderValue - min) / (max - min), 0, 1, 0)
  182. sliderBtn.Position = UDim2.new((sliderValue - min) / (max - min) - 0.05, 0, 0, 0)
  183. if callback then callback(sliderValue) end
  184. end
  185.  
  186. sliderBtn.InputBegan:Connect(function(input)
  187. if input.UserInputType == Enum.UserInputType.MouseButton1 then
  188. dragging = true
  189. end
  190. end)
  191.  
  192. sliderBtn.InputEnded:Connect(function(input)
  193. if input.UserInputType == Enum.UserInputType.MouseButton1 then
  194. dragging = false
  195. end
  196. end)
  197.  
  198. UserInputService.InputChanged:Connect(function(input)
  199. if dragging and input.UserInputType == Enum.UserInputType.MouseMovement then
  200. updateSlider(input.Position.X)
  201. end
  202. end)
  203.  
  204. return {
  205. Set = function(value)
  206. sliderValue = math.clamp(value, min, max)
  207. sliderFill.Size = UDim2.new((sliderValue - min) / (max - min), 0, 1, 0)
  208. sliderBtn.Position = UDim2.new((sliderValue - min) / (max - min) - 0.05, 0, 0, 0)
  209. if callback then callback(sliderValue) end
  210. end,
  211. Get = function()
  212. return sliderValue
  213. end
  214. }
  215. end
  216.  
  217. -- Dropdown control (updated: dropdown list outside container for top layering)
  218. function Library:CreateDropdown(name, options, callback)
  219. local isOpen = false
  220. local selectedIndex = 1
  221.  
  222. local frame = Instance.new("Frame")
  223. frame.Size = UDim2.new(1, 0, 0, 40)
  224. frame.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  225. frame.Parent = contentHolder
  226.  
  227. local label = createLabel(name)
  228. label.Size = UDim2.new(0.6, 0, 1, 0)
  229. label.Parent = frame
  230.  
  231. local dropdownBtn = Instance.new("TextButton")
  232. dropdownBtn.Size = UDim2.new(0.35, 0, 0.7, 0)
  233. dropdownBtn.Position = UDim2.new(0.6, 0, 0.15, 0)
  234. dropdownBtn.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
  235. dropdownBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
  236. dropdownBtn.Font = Enum.Font.SourceSansBold
  237. dropdownBtn.TextSize = 18
  238. dropdownBtn.Text = options[selectedIndex]
  239. dropdownBtn.Parent = frame
  240.  
  241. -- Dropdown list outside contentHolder for top layering & no clipping
  242. local dropdownList = Instance.new("Frame")
  243. dropdownList.Size = UDim2.new(0, 150, 0, #options * 30)
  244. dropdownList.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
  245. dropdownList.Visible = false
  246. dropdownList.ClipsDescendants = true
  247. dropdownList.BorderSizePixel = 0
  248. dropdownList.Parent = screenGui -- Directly parented to ScreenGui for highest z-index
  249.  
  250. local listLayout = Instance.new("UIListLayout")
  251. listLayout.Parent = dropdownList
  252.  
  253. for i, option in ipairs(options) do
  254. local optionBtn = Instance.new("TextButton")
  255. optionBtn.Size = UDim2.new(1, 0, 0, 30)
  256. optionBtn.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
  257. optionBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
  258. optionBtn.Font = Enum.Font.SourceSans
  259. optionBtn.TextSize = 18
  260. optionBtn.Text = option
  261. optionBtn.Parent = dropdownList
  262.  
  263. optionBtn.MouseButton1Click:Connect(function()
  264. selectedIndex = i
  265. dropdownBtn.Text = options[selectedIndex]
  266. dropdownList.Visible = false
  267. isOpen = false
  268. if callback then callback(options[selectedIndex]) end
  269. end)
  270. end
  271.  
  272. local function updateDropdownPosition()
  273. local absPos = dropdownBtn.AbsolutePosition
  274. local absSize = dropdownBtn.AbsoluteSize
  275.  
  276. -- Position dropdownList below dropdownBtn
  277. dropdownList.Position = UDim2.new(0, absPos.X, 0, absPos.Y + absSize.Y)
  278. dropdownList.Size = UDim2.new(0, absSize.X, 0, #options * 30)
  279. end
  280.  
  281. dropdownBtn.MouseButton1Click:Connect(function()
  282. isOpen = not isOpen
  283. dropdownList.Visible = isOpen
  284. if isOpen then
  285. updateDropdownPosition()
  286. end
  287. end)
  288.  
  289. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  290. if not gameProcessed and isOpen then
  291. -- Close dropdown if clicked outside dropdownBtn or dropdownList
  292. local mousePos = UserInputService:GetMouseLocation()
  293. local dpPos = dropdownList.AbsolutePosition
  294. local dpSize = dropdownList.AbsoluteSize
  295. local dbPos = dropdownBtn.AbsolutePosition
  296. local dbSize = dropdownBtn.AbsoluteSize
  297.  
  298. local inDropdownList = mousePos.X >= dpPos.X and mousePos.X <= dpPos.X + dpSize.X and
  299. mousePos.Y >= dpPos.Y and mousePos.Y <= dpPos.Y + dpSize.Y
  300. local inDropdownBtn = mousePos.X >= dbPos.X and mousePos.X <= dbPos.X + dbSize.X and
  301. mousePos.Y >= dbPos.Y and mousePos.Y <= dbPos.Y + dbSize.Y
  302.  
  303. if not inDropdownList and not inDropdownBtn then
  304. dropdownList.Visible = false
  305. isOpen = false
  306. end
  307. end
  308. end)
  309.  
  310. RunService.RenderStepped:Connect(function()
  311. if isOpen then
  312. updateDropdownPosition()
  313. end
  314. end)
  315.  
  316. return {
  317. Set = function(value)
  318. for i, option in ipairs(options) do
  319. if option == value then
  320. selectedIndex = i
  321. dropdownBtn.Text = value
  322. if callback then callback(value) end
  323. break
  324. end
  325. end
  326. end,
  327. Get = function()
  328. return options[selectedIndex]
  329. end
  330. }
  331. end
  332.  
  333. -- Button control
  334. function Library:CreateButton(name, callback)
  335. local button = Instance.new("TextButton")
  336. button.Size = UDim2.new(1, 0, 0, 40)
  337. button.BackgroundColor3 = Color3.fromRGB(80, 80, 80)
  338. button.TextColor3 = Color3.fromRGB(255, 255, 255)
  339. button.Font = Enum.Font.SourceSansBold
  340. button.TextSize = 20
  341. button.Text = name
  342. button.Parent = contentHolder
  343.  
  344. button.MouseButton1Click:Connect(function()
  345. if callback then callback() end
  346. end)
  347.  
  348. return button
  349. end
  350.  
  351. return Library
  352.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement