Advertisement
MayDayZen

Calculator

Aug 29th, 2022
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.45 KB | None | 0 0
  1. local Calculator = Instance.new("ScreenGui")
  2. local MainFrame = Instance.new("Frame")
  3. local UICorner = Instance.new("UICorner")
  4. local ButtonsFrame = Instance.new("Frame")
  5. local UICorner_2 = Instance.new("UICorner")
  6. local UIGridLayout = Instance.new("UIGridLayout")
  7. local _1 = Instance.new("TextButton")
  8. local UICorner_3 = Instance.new("UICorner")
  9. local UIPadding = Instance.new("UIPadding")
  10. local _2 = Instance.new("TextButton")
  11. local UICorner_4 = Instance.new("UICorner")
  12. local _3 = Instance.new("TextButton")
  13. local UICorner_5 = Instance.new("UICorner")
  14. local TextButton = Instance.new("TextButton")
  15. local UICorner_6 = Instance.new("UICorner")
  16. local _4 = Instance.new("TextButton")
  17. local UICorner_7 = Instance.new("UICorner")
  18. local _5 = Instance.new("TextButton")
  19. local UICorner_8 = Instance.new("UICorner")
  20. local _6 = Instance.new("TextButton")
  21. local UICorner_9 = Instance.new("UICorner")
  22. local TextButton_2 = Instance.new("TextButton")
  23. local UICorner_10 = Instance.new("UICorner")
  24. local _7 = Instance.new("TextButton")
  25. local UICorner_11 = Instance.new("UICorner")
  26. local _8 = Instance.new("TextButton")
  27. local UICorner_12 = Instance.new("UICorner")
  28. local _9 = Instance.new("TextButton")
  29. local UICorner_13 = Instance.new("UICorner")
  30. local TextButton_3 = Instance.new("TextButton")
  31. local UICorner_14 = Instance.new("UICorner")
  32. local _0 = Instance.new("TextButton")
  33. local UICorner_15 = Instance.new("UICorner")
  34. local TextButton_4 = Instance.new("TextButton")
  35. local UICorner_16 = Instance.new("UICorner")
  36. local TextButton_5 = Instance.new("TextButton")
  37. local UICorner_17 = Instance.new("UICorner")
  38. local TextButton_6 = Instance.new("TextButton")
  39. local UICorner_18 = Instance.new("UICorner")
  40. local C = Instance.new("TextButton")
  41. local UICorner_19 = Instance.new("UICorner")
  42. local TextButton_7 = Instance.new("TextButton")
  43. local UICorner_20 = Instance.new("UICorner")
  44. local TextButton_8 = Instance.new("TextButton")
  45. local UICorner_21 = Instance.new("UICorner")
  46. local TextButton_9 = Instance.new("TextButton")
  47. local UICorner_22 = Instance.new("UICorner")
  48. local UIPadding_2 = Instance.new("UIPadding")
  49. local NumFrame = Instance.new("Frame")
  50. local UIPadding_3 = Instance.new("UIPadding")
  51. local UICorner_23 = Instance.new("UICorner")
  52. local Text = Instance.new("TextLabel")
  53.  
  54. Calculator.Name = "Calculator"
  55. Calculator.Parent = game:GetService("CoreGui")
  56. Calculator.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  57.  
  58. MainFrame.Name = "MainFrame"
  59. MainFrame.Parent = Calculator
  60. MainFrame.AnchorPoint = Vector2.new(0.5, 0.5)
  61. MainFrame.BackgroundColor3 = Color3.fromRGB(255, 177, 255)
  62. MainFrame.Position = UDim2.new(0.5, 0, 0.49999994, 0)
  63. MainFrame.Size = UDim2.new(0, 250, 0, 400)
  64.  
  65. UICorner.Parent = MainFrame
  66.  
  67. ButtonsFrame.Name = "ButtonsFrame"
  68. ButtonsFrame.Parent = MainFrame
  69. ButtonsFrame.BackgroundColor3 = Color3.fromRGB(255, 135, 255)
  70. ButtonsFrame.Position = UDim2.new(0, 0, 0.248210549, 0)
  71. ButtonsFrame.Size = UDim2.new(0, 230, 0, 285)
  72.  
  73. UICorner_2.Parent = ButtonsFrame
  74.  
  75. UIGridLayout.Parent = ButtonsFrame
  76. UIGridLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
  77. UIGridLayout.SortOrder = Enum.SortOrder.LayoutOrder
  78. UIGridLayout.VerticalAlignment = Enum.VerticalAlignment.Center
  79. UIGridLayout.CellSize = UDim2.new(0, 50, 0, 50)
  80.  
  81. _1.Name = "1"
  82. _1.Parent = ButtonsFrame
  83. _1.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  84. _1.LayoutOrder = 1
  85. _1.Size = UDim2.new(0, 200, 0, 50)
  86. _1.AutoButtonColor = false
  87. _1.Font = Enum.Font.GothamBold
  88. _1.Text = "1"
  89. _1.TextColor3 = Color3.fromRGB(255, 255, 255)
  90. _1.TextScaled = true
  91. _1.TextSize = 14.000
  92. _1.TextWrapped = true
  93.  
  94. UICorner_3.Parent = _1
  95.  
  96. UIPadding.Parent = ButtonsFrame
  97. UIPadding.PaddingBottom = UDim.new(0, 5)
  98. UIPadding.PaddingLeft = UDim.new(0, 7)
  99. UIPadding.PaddingRight = UDim.new(0, 7)
  100. UIPadding.PaddingTop = UDim.new(0, 5)
  101.  
  102. _2.Name = "2"
  103. _2.Parent = ButtonsFrame
  104. _2.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  105. _2.LayoutOrder = 2
  106. _2.Size = UDim2.new(0, 200, 0, 50)
  107. _2.AutoButtonColor = false
  108. _2.Font = Enum.Font.GothamBold
  109. _2.Text = "2"
  110. _2.TextColor3 = Color3.fromRGB(255, 255, 255)
  111. _2.TextScaled = true
  112. _2.TextSize = 14.000
  113. _2.TextWrapped = true
  114.  
  115. UICorner_4.Parent = _2
  116.  
  117. _3.Name = "3"
  118. _3.Parent = ButtonsFrame
  119. _3.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  120. _3.LayoutOrder = 3
  121. _3.Size = UDim2.new(0, 200, 0, 50)
  122. _3.AutoButtonColor = false
  123. _3.Font = Enum.Font.GothamBold
  124. _3.Text = "3"
  125. _3.TextColor3 = Color3.fromRGB(255, 255, 255)
  126. _3.TextScaled = true
  127. _3.TextSize = 14.000
  128. _3.TextWrapped = true
  129.  
  130. UICorner_5.Parent = _3
  131.  
  132. TextButton.Name = "+"
  133. TextButton.Parent = ButtonsFrame
  134. TextButton.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  135. TextButton.LayoutOrder = 4
  136. TextButton.Size = UDim2.new(0, 200, 0, 50)
  137. TextButton.AutoButtonColor = false
  138. TextButton.Font = Enum.Font.GothamBold
  139. TextButton.Text = "+"
  140. TextButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  141. TextButton.TextScaled = true
  142. TextButton.TextSize = 14.000
  143. TextButton.TextWrapped = true
  144.  
  145. UICorner_6.Parent = TextButton
  146.  
  147. _4.Name = "4"
  148. _4.Parent = ButtonsFrame
  149. _4.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  150. _4.LayoutOrder = 5
  151. _4.Size = UDim2.new(0, 200, 0, 50)
  152. _4.AutoButtonColor = false
  153. _4.Font = Enum.Font.GothamBold
  154. _4.Text = "4"
  155. _4.TextColor3 = Color3.fromRGB(255, 255, 255)
  156. _4.TextScaled = true
  157. _4.TextSize = 14.000
  158. _4.TextWrapped = true
  159.  
  160. UICorner_7.Parent = _4
  161.  
  162. _5.Name = "5"
  163. _5.Parent = ButtonsFrame
  164. _5.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  165. _5.LayoutOrder = 6
  166. _5.Size = UDim2.new(0, 200, 0, 50)
  167. _5.AutoButtonColor = false
  168. _5.Font = Enum.Font.GothamBold
  169. _5.Text = "5"
  170. _5.TextColor3 = Color3.fromRGB(255, 255, 255)
  171. _5.TextScaled = true
  172. _5.TextSize = 14.000
  173. _5.TextWrapped = true
  174.  
  175. UICorner_8.Parent = _5
  176.  
  177. _6.Name = "6"
  178. _6.Parent = ButtonsFrame
  179. _6.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  180. _6.LayoutOrder = 7
  181. _6.Size = UDim2.new(0, 200, 0, 50)
  182. _6.AutoButtonColor = false
  183. _6.Font = Enum.Font.GothamBold
  184. _6.Text = "6"
  185. _6.TextColor3 = Color3.fromRGB(255, 255, 255)
  186. _6.TextScaled = true
  187. _6.TextSize = 14.000
  188. _6.TextWrapped = true
  189.  
  190. UICorner_9.Parent = _6
  191.  
  192. TextButton_2.Name = "-"
  193. TextButton_2.Parent = ButtonsFrame
  194. TextButton_2.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  195. TextButton_2.LayoutOrder = 8
  196. TextButton_2.Size = UDim2.new(0, 200, 0, 50)
  197. TextButton_2.AutoButtonColor = false
  198. TextButton_2.Font = Enum.Font.GothamBold
  199. TextButton_2.Text = "-"
  200. TextButton_2.TextColor3 = Color3.fromRGB(255, 255, 255)
  201. TextButton_2.TextScaled = true
  202. TextButton_2.TextSize = 14.000
  203. TextButton_2.TextWrapped = true
  204.  
  205. UICorner_10.Parent = TextButton_2
  206.  
  207. _7.Name = "7"
  208. _7.Parent = ButtonsFrame
  209. _7.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  210. _7.LayoutOrder = 9
  211. _7.Size = UDim2.new(0, 200, 0, 50)
  212. _7.AutoButtonColor = false
  213. _7.Font = Enum.Font.GothamBold
  214. _7.Text = "7"
  215. _7.TextColor3 = Color3.fromRGB(255, 255, 255)
  216. _7.TextScaled = true
  217. _7.TextSize = 14.000
  218. _7.TextWrapped = true
  219.  
  220. UICorner_11.Parent = _7
  221.  
  222. _8.Name = "8"
  223. _8.Parent = ButtonsFrame
  224. _8.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  225. _8.LayoutOrder = 10
  226. _8.Size = UDim2.new(0, 200, 0, 50)
  227. _8.AutoButtonColor = false
  228. _8.Font = Enum.Font.GothamBold
  229. _8.Text = "8"
  230. _8.TextColor3 = Color3.fromRGB(255, 255, 255)
  231. _8.TextScaled = true
  232. _8.TextSize = 14.000
  233. _8.TextWrapped = true
  234.  
  235. UICorner_12.Parent = _8
  236.  
  237. _9.Name = "9"
  238. _9.Parent = ButtonsFrame
  239. _9.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  240. _9.LayoutOrder = 11
  241. _9.Size = UDim2.new(0, 200, 0, 50)
  242. _9.AutoButtonColor = false
  243. _9.Font = Enum.Font.GothamBold
  244. _9.Text = "9"
  245. _9.TextColor3 = Color3.fromRGB(255, 255, 255)
  246. _9.TextScaled = true
  247. _9.TextSize = 14.000
  248. _9.TextWrapped = true
  249.  
  250. UICorner_13.Parent = _9
  251.  
  252. TextButton_3.Name = "/"
  253. TextButton_3.Parent = ButtonsFrame
  254. TextButton_3.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  255. TextButton_3.LayoutOrder = 12
  256. TextButton_3.Size = UDim2.new(0, 200, 0, 50)
  257. TextButton_3.AutoButtonColor = false
  258. TextButton_3.Font = Enum.Font.GothamBold
  259. TextButton_3.Text = "÷"
  260. TextButton_3.TextColor3 = Color3.fromRGB(255, 255, 255)
  261. TextButton_3.TextScaled = true
  262. TextButton_3.TextSize = 14.000
  263. TextButton_3.TextWrapped = true
  264.  
  265. UICorner_14.Parent = TextButton_3
  266.  
  267. _0.Name = "0"
  268. _0.Parent = ButtonsFrame
  269. _0.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  270. _0.LayoutOrder = 14
  271. _0.Size = UDim2.new(0, 200, 0, 50)
  272. _0.AutoButtonColor = false
  273. _0.Font = Enum.Font.GothamBold
  274. _0.Text = "0"
  275. _0.TextColor3 = Color3.fromRGB(255, 255, 255)
  276. _0.TextScaled = true
  277. _0.TextSize = 14.000
  278. _0.TextWrapped = true
  279.  
  280. UICorner_15.Parent = _0
  281.  
  282. TextButton_4.Name = "."
  283. TextButton_4.Parent = ButtonsFrame
  284. TextButton_4.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  285. TextButton_4.LayoutOrder = 13
  286. TextButton_4.Size = UDim2.new(0, 200, 0, 50)
  287. TextButton_4.AutoButtonColor = false
  288. TextButton_4.Font = Enum.Font.GothamBold
  289. TextButton_4.Text = "."
  290. TextButton_4.TextColor3 = Color3.fromRGB(255, 255, 255)
  291. TextButton_4.TextScaled = true
  292. TextButton_4.TextSize = 14.000
  293. TextButton_4.TextWrapped = true
  294.  
  295. UICorner_16.Parent = TextButton_4
  296.  
  297. TextButton_5.Name = "^"
  298. TextButton_5.Parent = ButtonsFrame
  299. TextButton_5.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  300. TextButton_5.LayoutOrder = 15
  301. TextButton_5.Size = UDim2.new(0, 200, 0, 50)
  302. TextButton_5.AutoButtonColor = false
  303. TextButton_5.Font = Enum.Font.GothamBold
  304. TextButton_5.Text = "aˣ"
  305. TextButton_5.TextColor3 = Color3.fromRGB(255, 255, 255)
  306. TextButton_5.TextScaled = true
  307. TextButton_5.TextSize = 14.000
  308. TextButton_5.TextWrapped = true
  309.  
  310. UICorner_17.Parent = TextButton_5
  311.  
  312. TextButton_6.Name = "*"
  313. TextButton_6.Parent = ButtonsFrame
  314. TextButton_6.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  315. TextButton_6.LayoutOrder = 16
  316. TextButton_6.Size = UDim2.new(0, 200, 0, 50)
  317. TextButton_6.AutoButtonColor = false
  318. TextButton_6.Font = Enum.Font.GothamBold
  319. TextButton_6.Text = "×"
  320. TextButton_6.TextColor3 = Color3.fromRGB(255, 255, 255)
  321. TextButton_6.TextScaled = true
  322. TextButton_6.TextSize = 14.000
  323. TextButton_6.TextWrapped = true
  324.  
  325. UICorner_18.Parent = TextButton_6
  326.  
  327. C.Name = "C"
  328. C.Parent = ButtonsFrame
  329. C.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  330. C.LayoutOrder = 17
  331. C.Size = UDim2.new(0, 200, 0, 50)
  332. C.AutoButtonColor = false
  333. C.Font = Enum.Font.GothamBold
  334. C.Text = "C"
  335. C.TextColor3 = Color3.fromRGB(255, 255, 255)
  336. C.TextScaled = true
  337. C.TextSize = 14.000
  338. C.TextWrapped = true
  339.  
  340. UICorner_19.Parent = C
  341.  
  342. TextButton_7.Name = "("
  343. TextButton_7.Parent = ButtonsFrame
  344. TextButton_7.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  345. TextButton_7.LayoutOrder = 18
  346. TextButton_7.Size = UDim2.new(0, 200, 0, 50)
  347. TextButton_7.AutoButtonColor = false
  348. TextButton_7.Font = Enum.Font.GothamBold
  349. TextButton_7.Text = "("
  350. TextButton_7.TextColor3 = Color3.fromRGB(255, 255, 255)
  351. TextButton_7.TextScaled = true
  352. TextButton_7.TextSize = 14.000
  353. TextButton_7.TextWrapped = true
  354.  
  355. UICorner_20.Parent = TextButton_7
  356.  
  357. TextButton_8.Name = ")"
  358. TextButton_8.Parent = ButtonsFrame
  359. TextButton_8.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  360. TextButton_8.LayoutOrder = 18
  361. TextButton_8.Size = UDim2.new(0, 200, 0, 50)
  362. TextButton_8.AutoButtonColor = false
  363. TextButton_8.Font = Enum.Font.GothamBold
  364. TextButton_8.Text = ")"
  365. TextButton_8.TextColor3 = Color3.fromRGB(255, 255, 255)
  366. TextButton_8.TextScaled = true
  367. TextButton_8.TextSize = 14.000
  368. TextButton_8.TextWrapped = true
  369.  
  370. UICorner_21.Parent = TextButton_8
  371.  
  372. TextButton_9.Name = "="
  373. TextButton_9.Parent = ButtonsFrame
  374. TextButton_9.BackgroundColor3 = Color3.fromRGB(255, 65, 255)
  375. TextButton_9.LayoutOrder = 19
  376. TextButton_9.Size = UDim2.new(0, 200, 0, 50)
  377. TextButton_9.AutoButtonColor = false
  378. TextButton_9.Font = Enum.Font.GothamBold
  379. TextButton_9.Text = "="
  380. TextButton_9.TextColor3 = Color3.fromRGB(255, 255, 255)
  381. TextButton_9.TextScaled = true
  382. TextButton_9.TextSize = 14.000
  383. TextButton_9.TextWrapped = true
  384.  
  385. UICorner_22.Parent = TextButton_9
  386.  
  387. UIPadding_2.Parent = MainFrame
  388. UIPadding_2.PaddingBottom = UDim.new(0, 10)
  389. UIPadding_2.PaddingLeft = UDim.new(0, 10)
  390. UIPadding_2.PaddingRight = UDim.new(0, 10)
  391. UIPadding_2.PaddingTop = UDim.new(0, 10)
  392.  
  393. NumFrame.Name = "NumFrame"
  394. NumFrame.Parent = MainFrame
  395. NumFrame.BackgroundColor3 = Color3.fromRGB(255, 135, 255)
  396. NumFrame.Size = UDim2.new(0, 230, 0, 85)
  397.  
  398. UIPadding_3.Parent = NumFrame
  399. UIPadding_3.PaddingBottom = UDim.new(0, 5)
  400. UIPadding_3.PaddingLeft = UDim.new(0, 7)
  401. UIPadding_3.PaddingRight = UDim.new(0, 7)
  402. UIPadding_3.PaddingTop = UDim.new(0, 5)
  403.  
  404. UICorner_23.Parent = NumFrame
  405.  
  406. Text.Name = "Text"
  407. Text.Parent = NumFrame
  408. Text.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
  409. Text.BackgroundTransparency = 1.000
  410. Text.Size = UDim2.new(0, 215, 0, 80)
  411. Text.Font = Enum.Font.Gotham
  412. Text.Text = "0"
  413. Text.TextColor3 = Color3.fromRGB(255, 255, 255)
  414. Text.TextScaled = true
  415. Text.TextSize = 50.000
  416. Text.TextWrapped = true
  417. Text.TextXAlignment = Enum.TextXAlignment.Right
  418.  
  419.  
  420.  
  421. local numLabel = Calculator.MainFrame.NumFrame.Text
  422.  
  423. for _, v in pairs(Calculator.MainFrame.ButtonsFrame:GetChildren()) do
  424. if v:IsA("TextButton") then
  425. if v.Name == "=" then
  426. v.MouseButton1Click:Connect(function()
  427. local ran, val = pcall(loadstring("local res = (".. numLabel.Text .."); return res"))
  428. if ran then
  429. numLabel.Text = val
  430. else
  431. numLabel.Text = "Error"
  432. end
  433. end)
  434. elseif v.Name == "C" then
  435. v.MouseButton1Click:Connect(function()
  436. numLabel.Text = "0"
  437. end)
  438. else
  439. v.MouseButton1Click:Connect(function()
  440. if numLabel.Text == "0" or numLabel.Text == "Error" then
  441. numLabel.Text = ""
  442. end
  443.  
  444. numLabel.Text = numLabel.Text.. v.Name
  445. end)
  446. end
  447. end
  448. end
  449.  
  450. local UserInputService = game:GetService("UserInputService")
  451. local gui = Calculator.MainFrame
  452.  
  453. local dragging
  454. local dragInput
  455. local dragStart
  456. local startPos
  457.  
  458. local function update(input)
  459. local delta = input.Position - dragStart
  460. gui.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
  461. end
  462.  
  463. gui.InputBegan:Connect(function(input)
  464. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  465. dragging = true
  466. dragStart = input.Position
  467. startPos = gui.Position
  468.  
  469. input.Changed:Connect(function()
  470. if input.UserInputState == Enum.UserInputState.End then
  471. dragging = false
  472. end
  473. end)
  474. end
  475. end)
  476.  
  477. gui.InputChanged:Connect(function(input)
  478. if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  479. dragInput = input
  480. end
  481. end)
  482.  
  483. UserInputService.InputChanged:Connect(function(input)
  484. if input == dragInput and dragging then
  485. update(input)
  486. end
  487. end)
  488.  
  489.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement