-- /// roblox 7chanhub script for Murderers VS Sheriffs - 7chan 2023
-- /// support server: discord.gg/7chan
-- /// tpa: 7chan hub roblox
-- /// Source: github.com/7chan-org

--> script variables
local UserInputService = game:GetService("UserInputService")
local CoreGui = game:GetService("CoreGui")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local localPlayer = Players.LocalPlayer
local mouse = localPlayer:GetMouse()

local screenGui = Instance.new("ScreenGui")
screenGui.Name = "7chanHub"
screenGui.Parent = CoreGui
screenGui.ResetOnSpawn = false

local container = Instance.new("TextLabel")
container.Name = "HubContainer"
container.Parent = screenGui
container.Size = UDim2.new(0, 500, 0, 300)
container.BackgroundTransparency = 1
container.Position = UDim2.new(0.5, 0, 0.5, 0)
container.TextColor3 = Color3.new(1,1,1)
container.TextSize = 14
container.TextXAlignment = Enum.TextXAlignment.Left
container.Text = "7chan Hub - roblox scripts | all functions enabled"
container.Active = true
container.Draggable = true

local aimBotCircle = Instance.new("ImageLabel")
aimBotCircle.Name = "AimbotCircle"
aimBotCircle.Parent = container
aimBotCircle.BackgroundTransparency = 1
aimBotCircle.Image = "rbxassetid://0"
aimBotCircle.ImageColor3 = Color3.new(1, 0, 0)
aimBotCircle.ScaleType = Enum.ScaleType.FitToContents
aimBotCircle.Size = UDim2.new(0, 200, 0, 200)
aimBotCircle.Visible = false
aimBotCircle.Position = UDim2.new(0.5, 0, 0.5, 0)

local aimBotSizeSlider = Instance.new("TextButton")
aimBotSizeSlider.Name = "AimbotSizeSlider"
aimBotSizeSlider.Parent = container
aimBotSizeSlider.Text = "Aimbot Circle Size: 100"
aimBotSizeSlider.BackgroundTransparency = 1
aimBotSizeSlider.Size = UDim2.new(0, 200, 0, 25)
aimBotSizeSlider.Position = UDim2.new(0, 0, 0, 275)

--> constants
local Hub = {}
local Aimbot = {}
local ESP = {}
local GameCheck = game.PlaceId ~= 135856908115931

--> functions

function Hub.onFocusLost()
    screenGui:Destroy()
end

function Hub.onDragStart()
    return true
end

function Aimbot.findNearestEnemy()
    local nearestEnemy = math.huge
    local nearestEnemyVector = Vector3.new()
    for i, plr in ipairs(Players:GetPlayers()) do
        if plr.Character and plr ~= localPlayer then
            local head = plr.Character:WaitForChild("Head")
            if head then
                local _, onScreen = workspace.CurrentCamera:WorldToScreenPoint(head.Position)
                if onScreen then
                    local magnitude = (mouse.Hit.p - head.Position).Magnitude
                    if magnitude < nearestEnemy then
                        nearestEnemy = magnitude
                        nearestEnemyVector = head.Position
                    end
                end
            end
        end
    end
    return nearestEnemyVector
end

function Aimbot.aimAtTarget(target)
    local velocityVector = target.Velocity * (mouse.Hit.p - target.Part.Position).Magnitude / 90
    local aimPosition = target.Part.CFrame:ToWorldSpace(CFrame.new(0, 0, -1).LookVector * 10 + velocityVector)
    mouse.Hit.p = aimPosition
end

function ESP.onCharacterAdded(character)
    local hrp = character:WaitForChild("HumanoidRootPart")
    local head = character:WaitForChild("Head")
    local namePlate = Instance.new("TextLabel")
    namePlate.Parent = hrp
    namePlate.Name = "Nameplate"
    namePlate.Text = character.Parent.Name
    namePlate.BackgroundTransparency = 1
    namePlate.TextColor3 = Color3.new(1,1,1)
    namePlate.Size = UDim2.new(0, 200, 0, 25)
    namePlate.TextXAlignment = Enum.TextXAlignment.Left
    namePlate.TextSize = 14

    local box = Instance.new("BoxHandleAdornment")
    box.Parent = hrp
    box.Adornee = hrp
    box.AlwaysOnTop = true
    box.Transparency = NumberSequence.new(0)
    box.Size = Vector3.new(1,2,1) * hrp.Size.X / 2

    local updateFunction = RunService.Heartbeat:Connect(function()
        if not hrp then
            updateFunction:Disconnect()
        else
            namePlate.TextColor3 = Color3.new(1,1,1)
            namePlate.Text = character.Parent.Name
            local distanceToPlayer = (localPlayer.Character.HumanoidRootPart.Position - hrp.Position).Magnitude
            namePlate.Text = string.format("%s (%.1fm)", character.Parent.Name, distanceToPlayer)

            local headPosition, onScreen = workspace.CurrentCamera:WorldToScreenPoint(head.Position)
            if onScreen then
                box.Color3 = Color3.new(1,0,0)
            else
                box.Color3 = Color3.new(1,1,1)
            end

            local aimPosition = Aimbot.findNearestEnemy()
            local distanceToAimPosition = (hrp.Position - aimPosition).Magnitude
            local distanceThreshold = aimBotSizeSlider.Size.X.Scale * 100
            if distanceToAimPosition < distanceThreshold then
                aimBotCircle.Visible = true
                aimBotCircle.ImageColor3 = Color3.new(0,1,0)
            else
                aimBotCircle.Visible = false
            end

            aimBotCircle.Size = UDim2.new(aimBotSizeSlider.Size.X.Scale / 50, 0, aimBotSizeSlider.Size.X.Scale / 50, 0)
            aimBotCircle.Position = UDim2.new(mouse.Hit.p.X / screenGui.AbsoluteSize.X - 1, 0,
                mouse.Hit.p.Y / screenGui.AbsoluteSize.Y - 1, 0)
        end
    end)
end

--> setup functions

function Hub:setup()
    local children = container:GetChildren()
    for i, child in ipairs(children) do
        if child:IsA("TextButton") then
            child.Activated:Connect(function()
                child.TextColor3 = Color3.new(0.5,1,0.5)
                wait(0.1)
                child.TextColor3 = Color3.new(1,1,1)
            end)
        end
    end

    local function onInputBegan(inputObject, gameProcessed)
        if inputObject.KeyCode == Enum.KeyCode.F1 then
            Hub.openHub()
        end
    end
    UserInputService.InputBegan:Connect(onInputBegan)
end

function ESP:setup()
    local children = ESP:FindFirstChildOfClass("Model")
    if children then
        for i, child in ipairs(children:GetChildren()) do
            if child:IsA("Model") then
                ESP.onCharacterAdded(child)
            end
        end
    else
        children.ChildAdded:Connect(function(child)
            if child:IsA("Model") then
                ESP.onCharacterAdded(child)
            end
        end)
    end
end

function Aimbot:setup()
    local canAim = false
    local aimPosition = Vector3.new()
    local lastAimPosition = Vector3.new()
    local aimPositionChangedConnection

    local function onInputBegan(inputObject, gameProcessed)
        if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
            canAim = true
        end
    end
    UserInputService.InputBegan:Connect(onInputBegan)

    local function onInputEnded(inputObject, gameProcessed)
        if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
            canAim = false
        end
    end
    UserInputService.InputEnded:Connect(onInputEnded)

    local function onCameraChanged(camera)
        local _, onScreen = workspace.CurrentCamera:WorldToScreenPoint(camera.CFrame.p)
        if onScreen then
            aimPositionChangedConnection = camera:GetPropertyChangedSignal("CFrame"):Connect(function()
                lastAimPosition = camera.CFrame.p
            end)
        else
            aimPositionChangedConnection:Disconnect()
        end
    end
    workspace.CurrentCamera:GetPropertyChangedSignal("CFrame"):Connect(onCameraChanged)

    local function onHeartbeat()
        if canAim then
            aimPosition = Aimbot.findNearestEnemy()
            Aimbot.aimAtTarget(aimPosition)
        end
    end
    RunService.Heartbeat:Connect(onHeartbeat)

    local function onMouseMoved(x, y)
        lastAimPosition = Vector3.new(x, y, lastAimPosition.Z)
    end
    mouse.Move:Connect(onMouseMoved)

    local function onUIStep()
        if mouse.Target then
            aimBotCircle.Visible = false
        else
            aimBotCircle.Visible = true
        end
    end
    RunService.RenderStepped:Connect(onUIStep)
end

function Aimbot.openHub()
    Hub:setup()
end

function ESP.openHub()
    ESP:setup()
end

function Aimbot.openHub()
    Hub:setup()
end

if GameCheck then return print("Error: This script must be run on Murderers VS Sheriffs!") end

Hub:setup()
ESP:setup()
Aimbot:setup()
