Advertisement
SigmaBoy456

GUI Toggle Example roblox script

Sep 24th, 2024
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. local GUI = Instance.new("ScreenGui", game.CoreGui)
  2. GUI.Name = "my gui"
  3. local mainFrame = Instance.new("Frame", GUI)
  4. mainFrame.Name = "My frame"
  5. mainFrame.Size = UDim2.new(0, 100, 0, 100)
  6. mainFrame.Position = UDim2.new(0, 0, 0, 0)
  7. mainFrame.BackgroundColor3 = Color3.new(1, 1, 1)
  8. mainFrame.Active = true
  9. mainFrame.Draggable = true
  10. local title = Instance.new("TextLabel", mainFrame)
  11. title.Size = UDim2.new(0, 100, 0, 20)
  12. title.Name = "My title"
  13. title.BackgroundColor3 = Color3.new(1, 1, 1)
  14. title.Position = UDim2.new(0, 0, 0, 0)
  15. title.Text = "Example GUI toggle"
  16. title.TextScaled = true
  17. title.Font = Enum.Font.Code
  18. -- Function Toggle
  19.  
  20. local isOn = false
  21.  
  22. local toggle = Instance.new("TextButton", mainFrame)
  23. toggle.Size = UDim2.new(0, 100, 0, 30)
  24. toggle.Position = UDim2.new(0, 0, 0, 30)
  25. toggle.Name = "My toggle"
  26. toggle.BackgroundColor3 = Color3.new(1, 1, 1)
  27. toggle.Text = "Not Toggled"
  28. toggle.TextScaled = true
  29.  
  30. toggle.MouseButton1Click:Connect(function()
  31. isOn = not isOn
  32. if isOn then
  33. toggle.Text = "Toggled"
  34. while isOn do
  35. wait(1)
  36. print("hello world")
  37. if not isOn then
  38. toggle.Text = "Not Toggled"
  39. break
  40. end
  41. end
  42. end
  43. end)
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement