Advertisement
aesnike

TP-CLaUDE

Oct 26th, 2024 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. -- Button state saving system
  2. local HttpService = game:GetService("HttpService")
  3. local buttonStates = {}
  4.  
  5. -- Function to save button states
  6. local function saveButtonStates()
  7. local success, err = pcall(function()
  8. local saveData = HttpService:JSONEncode(buttonStates)
  9. writefile("buttonStates.json", saveData)
  10. end)
  11. end
  12.  
  13. -- Function to load button states
  14. local function loadButtonStates()
  15. if isfile("buttonStates.json") then
  16. local success, data = pcall(function()
  17. return HttpService:JSONDecode(readfile("buttonStates.json"))
  18. end)
  19. if success then
  20. buttonStates = data
  21. end
  22. end
  23. end
  24.  
  25. -- Modified createToggleButton function (replace the existing one)
  26. local function createToggleButton(number, name, onClick)
  27. local button = Instance.new("TextButton")
  28. button.Size = UDim2.new(0.7, 0, 0, 30)
  29. button.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  30. button.Text = name
  31. button.TextColor3 = Color3.fromRGB(255, 255, 255)
  32. button.Font = Enum.Font.SourceSansBold
  33. button.TextSize = 14
  34. button.LayoutOrder = number
  35. button.Parent = MainFrame
  36. button.ZIndex = 2
  37.  
  38. local corner = Instance.new("UICorner")
  39. corner.CornerRadius = UDim.new(0.3, 0)
  40. corner.Parent = button
  41.  
  42. -- Load saved state
  43. local isEnabled = buttonStates[name] or false
  44. button.BackgroundColor3 = isEnabled and Color3.fromRGB(0, 0, 255) or Color3.fromRGB(0, 0, 0)
  45.  
  46. -- If button was previously enabled, activate it
  47. if isEnabled then
  48. onClick(true)
  49. end
  50.  
  51. button.MouseButton1Click:Connect(function()
  52. isEnabled = not isEnabled
  53. button.BackgroundColor3 = isEnabled and Color3.fromRGB(0, 0, 255) or Color3.fromRGB(0, 0, 0)
  54. buttonStates[name] = isEnabled
  55. saveButtonStates()
  56. onClick(isEnabled)
  57. end)
  58.  
  59. return button
  60. end
  61.  
  62. -- Load saved states when script starts
  63. loadButtonStates()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement