local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local CoreGui = game:GetService("CoreGui")
local HttpService = game:GetService("HttpService")

local LocalPlayer = Players.LocalPlayer

-- Create the ScreenGui
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "ScriptGUI"
ScreenGui.ResetOnSpawn = false -- Ensures the GUI persists after respawn
ScreenGui.Parent = CoreGui

-- Create the Frame
local Frame = Instance.new("Frame")
Frame.Name = "ButtonFrame"
Frame.Parent = ScreenGui
Frame.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
Frame.Position = UDim2.new(1, -110, 0, 10)
Frame.Size = UDim2.new(0, 100, 0, 110)
Frame.Visible = false

-- Create the Aimbot button
local AimbotButton = Instance.new("TextButton")
AimbotButton.Name = "AimbotButton"
AimbotButton.Parent = Frame
AimbotButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
AimbotButton.Position = UDim2.new(0, 0, 0, 10)
AimbotButton.Size = UDim2.new(1, 0, 0, 40)
AimbotButton.Font = Enum.Font.SourceSans
AimbotButton.Text = "Aimbot v1"
AimbotButton.TextColor3 = Color3.fromRGB(255, 255, 255)
AimbotButton.TextSize = 14

-- Create the ESP button
local EspButton = Instance.new("TextButton")
EspButton.Name = "EspButton"
EspButton.Parent = Frame
EspButton.BackgroundColor3 = Color3.fromRGB(0, 0, 255)
EspButton.Position = UDim2.new(0, 0, 0, 60)
EspButton.Size = UDim2.new(1, 0, 0, 40)
EspButton.Font = Enum.Font.SourceSans
EspButton.Text = "ESP v1"
EspButton.TextColor3 = Color3.fromRGB(255, 255, 255)
EspButton.TextSize = 14

-- Function to load external scripts securely
local function secureLoadScript(url)
    local success, result = pcall(function()
        return HttpService:GetAsync(url, true)
    end)
    if success then
        local func, loadErr = loadstring(result)
        if func then
            pcall(func)
        else
            warn("Error loading script: " .. (loadErr or "Unknown error"))
        end
    else
        warn("Failed to fetch script from URL: " .. url)
    end
end

-- Aimbot button click event
AimbotButton.MouseButton1Click:Connect(function()
    secureLoadScript("https://a.f55.space/get/aimbot_v1.txt")
end)

-- ESP button click event
EspButton.MouseButton1Click:Connect(function()
    secureLoadScript("https://a.f55.space/get/esp_v1.txt")
end)

-- Toggle frame visibility with Alt key
UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if not gameProcessed and input.KeyCode == Enum.KeyCode.RightAlt then
        Frame.Visible = not Frame.Visible
    end
end)
