CCCPaste

My First Hub

local Rayfield = nil
local success, lib = pcall(function()
    return loadstring(game:HttpGet("https://sirius.menu/rayfield"))()
end)

if success and lib then
    Rayfield = lib
else
    warn("Failed to load Rayfield UI. Check connection or the library link.")
    return
end

-- =====================================
-- Services & Globals
-- =====================================
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

getgenv().UniversalSettings = getgenv().UniversalSettings or {
    WalkSpeed = 16,
    JumpPower = 50,
    FlySpeed = 50,
    ESPEnabled = false,
    ChamsEnabled = false,
    NametagsEnabled = true,
    AntiAFK = true,
    FlyEnabled = false,
}

local Settings = getgenv().UniversalSettings
local Highlights = {}
local NametagHolder = {}

-- =====================================
-- UI Window
-- =====================================
local Window = Rayfield:CreateWindow({
    Name = "🌐 Clints Hub",
    LoadingTitle = "Loading Clints Hub...",
    LoadingSubtitle = "Rayfield UI",
    ConfigurationSaving = {
        Enabled = true,
        FolderName = "UniversalHubConfig",
        FileName = "RayfieldUniversal"
    },
    Discord = {
        Enabled = false
    },
    KeySystem = false
})

-- Tabs
local mainTab = Window:CreateTab("Main", 4483345998)
local playerTab = Window:CreateTab("Player", 4483345998)
local visualsTab = Window:CreateTab("Visuals", 6023426915)
local utilitiesTab = Window:CreateTab("Utilities", 4670953385)
local settingsTab = Window:CreateTab("Settings", 6034818375)

-- =====================================
-- Main Tab
-- =====================================
mainTab:CreateButton({
    Name = "Reset Character",
    Callback = function()
        LocalPlayer:LoadCharacter()
    end
})

mainTab:CreateButton({
    Name = "Center Camera on Character",
    Callback = function()
        if Character and Character:FindFirstChild("HumanoidRootPart") then
            workspace.CurrentCamera.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0, 5, -10)
        end
    end
})

mainTab:CreateButton({
    Name = "Copy Player List",
    Callback = function()
        local names = {}
        for _, p in pairs(Players:GetPlayers()) do
            table.insert(names, p.Name)
        end
        pcall(function() setclipboard(table.concat(names, ", ")) end)
        Rayfield:Notify({Title = "Copied", Content = "Player list copied to clipboard."})
    end
})

-- =====================================
-- Player Tab
-- =====================================
playerTab:CreateSlider({
    Name = "WalkSpeed",
    Range = {8, 300},
    Increment = 1,
    Suffix = "studs/s",
    CurrentValue = Settings.WalkSpeed,
    Callback = function(Value)
        Settings.WalkSpeed = Value
        if Humanoid then Humanoid.WalkSpeed = Value end
    end
})

playerTab:CreateSlider({
    Name = "JumpPower",
    Range = {10, 300},
    Increment = 1,
    Suffix = "power",
    CurrentValue = Settings.JumpPower,
    Callback = function(Value)
        Settings.JumpPower = Value
        if Humanoid then Humanoid.JumpPower = Value end
    end
})

-- ✈️ Fly Toggle
playerTab:CreateToggle({
    Name = "Enable Fly",
    CurrentValue = Settings.FlyEnabled,
    Callback = function(state)
        Settings.FlyEnabled = state
        local root = Character:FindFirstChild("HumanoidRootPart")
        if not root then return end

        if state then
            local bv = Instance.new("BodyVelocity")
            bv.Name = "FlyBV"
            bv.MaxForce = Vector3.new(1e5, 1e5, 1e5)
            bv.Parent = root

            local bg = Instance.new("BodyGyro")
            bg.Name = "FlyBG"
            bg.MaxTorque = Vector3.new(4e5, 4e5, 4e5)
            bg.CFrame = root.CFrame
            bg.Parent = root

            local flySpeed = Settings.FlySpeed
            local moveDir = Vector3.new()

            local keys = {W=false,S=false,A=false,D=false,Space=false,Shift=false}

            local function update()
                local cam = workspace.CurrentCamera
                local dir = Vector3.new()
                if keys.W then dir = dir + cam.CFrame.LookVector end
                if keys.S then dir = dir - cam.CFrame.LookVector end
                if keys.A then dir = dir - cam.CFrame.RightVector end
                if keys.D then dir = dir + cam.CFrame.RightVector end
                if keys.Space then dir = dir + Vector3.new(0,1,0) end
                if keys.Shift then dir = dir - Vector3.new(0,1,0) end
                if dir.Magnitude > 0 then
                    bv.Velocity = dir.Unit * flySpeed
                    bg.CFrame = CFrame.new(root.Position, root.Position + cam.CFrame.LookVector)
                else
                    bv.Velocity = Vector3.new()
                end
            end

            local inputBegan = UserInputService.InputBegan:Connect(function(input, gpe)
                if gpe then return end
                if input.KeyCode == Enum.KeyCode.W then keys.W = true end
                if input.KeyCode == Enum.KeyCode.S then keys.S = true end
                if input.KeyCode == Enum.KeyCode.A then keys.A = true end
                if input.KeyCode == Enum.KeyCode.D then keys.D = true end
                if input.KeyCode == Enum.KeyCode.Space then keys.Space = true end
                if input.KeyCode == Enum.KeyCode.LeftShift then keys.Shift = true end
            end)

            local inputEnded = UserInputService.InputEnded:Connect(function(input)
                if input.KeyCode == Enum.KeyCode.W then keys.W = false end
                if input.KeyCode == Enum.KeyCode.S then keys.S = false end
                if input.KeyCode == Enum.KeyCode.A then keys.A = false end
                if input.KeyCode == Enum.KeyCode.D then keys.D = false end
                if input.KeyCode == Enum.KeyCode.Space then keys.Space = false end
                if input.KeyCode == Enum.KeyCode.LeftShift then keys.Shift = false end
            end)

            local step = RunService.RenderStepped:Connect(update)

            Settings._FlyCleanup = function()
                inputBegan:Disconnect()
                inputEnded:Disconnect()
                step:Disconnect()
                bv:Destroy()
                bg:Destroy()
            end
        else
            if Settings._FlyCleanup then
                Settings._FlyCleanup()
                Settings._FlyCleanup = nil
            end
        end
    end
})

playerTab:CreateInput({
    Name = "Teleport to Player",
    PlaceholderText = "Player Name",
    RemoveTextAfterFocusLost = true,
    Callback = function(val)
        local target = Players:FindFirstChild(val)
        if target and target.Character and target.Character:FindFirstChild("HumanoidRootPart") then
            Character:WaitForChild("HumanoidRootPart").CFrame = target.Character.HumanoidRootPart.CFrame + Vector3.new(0,3,0)
        else
            Rayfield:Notify({Title="Teleport Failed", Content="Player not found or no HRP."})
        end
    end
})

playerTab:CreateButton({
    Name = "Teleport to Mouse",
    Callback = function()
        local mouse = LocalPlayer:GetMouse()
        if mouse and mouse.Hit then
            Character:WaitForChild("HumanoidRootPart").CFrame = mouse.Hit + Vector3.new(0,3,0)
        end
    end
})

-- =====================================
-- Visuals Tab
-- =====================================

local function createHighlight(char, color)
    if not char or Highlights[char] then return end
    local h = Instance.new("Highlight")
    h.Name = "ESPHighlight"
    h.Adornee = char
    h.FillColor = color or Color3.fromHSV(tick()%10/10,1,1)
    h.FillTransparency = 0.5
    h.OutlineTransparency = 0.4
    h.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
    h.Parent = game:GetService("CoreGui")
    Highlights[char] = h
end

local function removeHighlight(char)
    if Highlights[char] then
        Highlights[char]:Destroy()
        Highlights[char] = nil
    end
end

visualsTab:CreateToggle({
    Name = "ESP",
    CurrentValue = Settings.ESPEnabled,
    Callback = function(state)
        Settings.ESPEnabled = state
        if not state then
            for c,_ in pairs(Highlights) do removeHighlight(c) end
        else
            for _,p in pairs(Players:GetPlayers()) do
                if p ~= LocalPlayer and p.Character then createHighlight(p.Character) end
            end
        end
    end
})

visualsTab:CreateToggle({
    Name = "Chams",
    CurrentValue = Settings.ChamsEnabled,
    Callback = function(state)
        Settings.ChamsEnabled = state
        for _, p in pairs(Players:GetPlayers()) do
            if p ~= LocalPlayer and p.Character then
                for _, part in pairs(p.Character:GetDescendants()) do
                    if part:IsA("BasePart") then
                        if state then
                            if not part:FindFirstChild("Cham") then
                                local box = Instance.new("SelectionBox")
                                box.Name = "Cham"
                                box.Adornee = part
                                box.Parent = part
                            end
                        else
                            if part:FindFirstChild("Cham") then
                                part.Cham:Destroy()
                            end
                        end
                    end
                end
            end
        end
    end
})

visualsTab:CreateToggle({
    Name = "Nametags",
    CurrentValue = Settings.NametagsEnabled,
    Callback = function(state)
        Settings.NametagsEnabled = state
        if not state then
            for _, gui in pairs(NametagHolder) do
                if gui then gui:Destroy() end
            end
            NametagHolder = {}
        end
    end
})

-- =====================================
-- Utilities Tab
-- =====================================

utilitiesTab:CreateToggle({
    Name = "Anti-AFK",
    CurrentValue = Settings.AntiAFK,
    Callback = function(state)
        Settings.AntiAFK = state
        if state then
            getgenv().AntiAFKConnection = game:GetService("UserInputService").Idled:Connect(function()
                game:GetService("VirtualUser"):ClickButton2(Vector2.new())
            end)
        else
            if getgenv().AntiAFKConnection then
                getgenv().AntiAFKConnection:Disconnect()
                getgenv().AntiAFKConnection = nil
            end
        end
    end
})

utilitiesTab:CreateButton({
    Name = "Get Nearest Player",
    Callback = function()
        local root = Character:FindFirstChild("HumanoidRootPart")
        if not root then return end
        local nearest, dist = nil, math.huge
        for _, p in pairs(Players:GetPlayers()) do
            if p ~= LocalPlayer and p.Character and p.Character:FindFirstChild("HumanoidRootPart") then
                local d = (p.Character.HumanoidRootPart.Position - root.Position).Magnitude
                if d < dist then
                    nearest = p
                    dist = d
                end
            end
        end
        if nearest then
            Rayfield:Notify({Title="Nearest Player", Content=nearest.Name.." ("..math.floor(dist).." studs)"})
        else
            Rayfield:Notify({Title="Nearest Player", Content="No one nearby"})
        end
    end
})

-- =====================================
-- Settings Tab
-- =====================================

settingsTab:CreateKeybind({
    Name = "Toggle UI",
    CurrentKeybind = Enum.KeyCode.RightShift,
    HoldToInteract = false,
    Callback = function()
        Rayfield:Toggle()
    end
})

settingsTab:CreateInput({
    Name = "Set Fly Speed",
    PlaceholderText = tostring(Settings.FlySpeed),
    RemoveTextAfterFocusLost = true,
    Callback = function(val)
        local n = tonumber(val)
        if n then Settings.FlySpeed = n end
    end
})

settingsTab:CreateButton({
    Name = "Unload Script",
    Callback = function()
        for c,_ in pairs(Highlights) do removeHighlight(c) end
        if getgenv().AntiAFKConnection then
            getgenv().AntiAFKConnection:Disconnect()
            getgenv().AntiAFKConnection = nil
        end
        Rayfield:Destroy()
    end
})

-- =====================================
-- Nametags Runtime
-- =====================================
RunService.Heartbeat:Connect(function()
    for _, p in pairs(Players:GetPlayers()) do
        if p ~= LocalPlayer then
            if Settings.NametagsEnabled and p.Character and p.Character:FindFirstChild("Head") then
                if not NametagHolder[p] then
                    local gui = Instance.new("BillboardGui")
                    gui.Name = "Nametag"
                    gui.Size = UDim2.new(0,150,0,50)
                    gui.StudsOffset = Vector3.new(0,2.5,0)
                    gui.AlwaysOnTop = true
                    gui.MaxDistance = 1000

                    local label = Instance.new("TextLabel", gui)
                    label.Size = UDim2.new(1,0,1,0)
                    label.BackgroundTransparency = 1
                    label.Text = p.Name
                    label.TextColor3 = Color3.fromRGB(255,255,255)
                    label.Font = Enum.Font.SourceSansBold
                    label.TextScaled = true
                    label.TextStrokeTransparency = 0.6

                    gui.Parent = p.Character.Head
                    NametagHolder[p] = gui
                end
            else
                if NametagHolder[p] then
                    NametagHolder[p]:Destroy()
                    NametagHolder[p] = nil
                end
            end
        end
    end
end)

-- =====================================
-- Keep WS/JP synced
-- =====================================
RunService.Heartbeat:Connect(function()
    if Humanoid then
        if Humanoid.WalkSpeed ~= Settings.WalkSpeed then
            Humanoid.WalkSpeed = Settings.WalkSpeed
        end
        if Humanoid.JumpPower ~= Settings.JumpPower then
            Humanoid.JumpPower = Settings.JumpPower
        end
    end
end)

Rayfield:Notify({Title="✅ Universal Hub", Content="Rayfield version loaded. RightShift to toggle UI."})