Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Button state saving system
- local HttpService = game:GetService("HttpService")
- local buttonStates = {}
- -- Function to save button states
- local function saveButtonStates()
- local success, err = pcall(function()
- local saveData = HttpService:JSONEncode(buttonStates)
- writefile("buttonStates.json", saveData)
- end)
- end
- -- Function to load button states
- local function loadButtonStates()
- if isfile("buttonStates.json") then
- local success, data = pcall(function()
- return HttpService:JSONDecode(readfile("buttonStates.json"))
- end)
- if success then
- buttonStates = data
- end
- end
- end
- -- Modified createToggleButton function (replace the existing one)
- local function createToggleButton(number, name, onClick)
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0.7, 0, 0, 30)
- button.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
- button.Text = name
- button.TextColor3 = Color3.fromRGB(255, 255, 255)
- button.Font = Enum.Font.SourceSansBold
- button.TextSize = 14
- button.LayoutOrder = number
- button.Parent = MainFrame
- button.ZIndex = 2
- local corner = Instance.new("UICorner")
- corner.CornerRadius = UDim.new(0.3, 0)
- corner.Parent = button
- -- Load saved state
- local isEnabled = buttonStates[name] or false
- button.BackgroundColor3 = isEnabled and Color3.fromRGB(0, 0, 255) or Color3.fromRGB(0, 0, 0)
- -- If button was previously enabled, activate it
- if isEnabled then
- onClick(true)
- end
- button.MouseButton1Click:Connect(function()
- isEnabled = not isEnabled
- button.BackgroundColor3 = isEnabled and Color3.fromRGB(0, 0, 255) or Color3.fromRGB(0, 0, 0)
- buttonStates[name] = isEnabled
- saveButtonStates()
- onClick(isEnabled)
- end)
- return button
- end
- -- Load saved states when script starts
- loadButtonStates()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement