-- ==========================================
-- 1. 서비스 및 기본 플레이어 설정
-- ==========================================
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local CoreGui = game:GetService("CoreGui")
local UserInputService = game:GetService("UserInputService")

local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Mouse = LocalPlayer:GetMouse()

-- ==========================================
-- 2. 핵심 글로벌 상태 변수 설정
-- ==========================================
local FLYING = false
local QEfly = true
local iyflyspeed = 1
local walkspeed_val = 16
local NOCLIP = false

local CONTROL = {F = 0, B = 0, L = 0, R = 0, Q = 0, E = 0}
local lCONTROL = {F = 0, B = 0, L = 0, R = 0, Q = 0, E = 0}
local SPEED = 0

local targetPlayerName = ""
local loopTeleportActive = false
local loopTeleportConn = nil

-- [ESP 설정]
local ESP_ENABLED = false

-- [에임봇 & 오토샷 설정]
local AimEnabled = false -- 기본은 꺼짐 (UI에서 토글 가능)
local AutoShotEnabled = false -- 기본은 꺼짐 (UI에서 토글 가능)
local FovRadius = 100

local IsMobile = UserInputService.TouchEnabled and not UserInputService.KeyboardEnabled
local IsRightMouseDown = false
local IsRKeyDown = false
local LockedTarget = nil

-- ==========================================
-- 3. FOV 드로잉 객체 생성
-- ==========================================
local FovCircle = Drawing.new("Circle")
FovCircle.Color = Color3.fromRGB(255, 255, 255)
FovCircle.Thickness = 1
FovCircle.Filled = false
FovCircle.Visible = false -- 에임봇이 켜졌을 때만 활성화되도록 유동적 처리

-- ==========================================
-- 4. 보조 유틸리티 함수 정의
-- ==========================================
local function getRoot(char)
	return char:FindFirstChild("HumanoidRootPart") or char:FindFirstChild("Torso") or char:FindFirstChild("UpperTorso")
end

-- Fly 기능 원본 비활성화
function NOFLY()
	FLYING = false
	if LocalPlayer.Character and LocalPlayer.Character:FindFirstChildWhichIsA("Humanoid") then
		LocalPlayer.Character:FindFirstChildWhichIsA("Humanoid").PlatformStand = false
	end
end

-- Fly 기능 원본 활성화 (카메라 기반 제어)
function sFLY()
	local camera = workspace.CurrentCamera
	local char = LocalPlayer.Character
	if not char then return end
	local root = getRoot(char)
	if not root then return end
	
	NOFLY()
	task.wait(0.1)
	FLYING = true
	
	local BG = Instance.new("BodyGyro")
	local BV = Instance.new("BodyVelocity")
	
	BG.P = 9e4
	BG.Parent = root
	BG.MaxTorque = Vector3.new(9e9, 9e9, 9e9)
	BG.CFrame = root.CFrame
	
	BV.Parent = root
	BV.Velocity = Vector3.new(0, 0, 0)
	BV.MaxForce = Vector3.new(9e9, 9e9, 9e9)
	
	task.spawn(function()
		repeat
			task.wait()
			if char:FindFirstChildWhichIsA("Humanoid") then
				char:FindFirstChildWhichIsA("Humanoid").PlatformStand = true
			end
			
			if (CONTROL.L + CONTROL.R) ~= 0 or (CONTROL.F + CONTROL.B) ~= 0 or (CONTROL.Q + CONTROL.E) ~= 0 then
				SPEED = 35 * iyflyspeed
			elseif (CONTROL.L + CONTROL.R) == 0 and (CONTROL.F + CONTROL.B) == 0 and (CONTROL.Q + CONTROL.E) == 0 and SPEED ~= 0 then
				SPEED = 0
			end
			
			if (CONTROL.L + CONTROL.R) ~= 0 or (CONTROL.F + CONTROL.B) ~= 0 or (CONTROL.Q + CONTROL.E) ~= 0 then
				BV.Velocity = ((camera.CFrame.LookVector * (CONTROL.F + CONTROL.B)) + ((camera.CFrame * CFrame.new(CONTROL.L + CONTROL.R, (CONTROL.F + CONTROL.B + CONTROL.Q + CONTROL.E) * 0.2, 0).p) - camera.CFrame.p)) * SPEED
				lCONTROL = {F = CONTROL.F, B = CONTROL.B, L = CONTROL.L, R = CONTROL.R}
			elseif (CONTROL.L + CONTROL.R) == 0 and (CONTROL.F + CONTROL.B) == 0 and (CONTROL.Q + CONTROL.E) == 0 and SPEED ~= 0 then
				BV.Velocity = ((camera.CFrame.LookVector * (lCONTROL.F + lCONTROL.B)) + ((camera.CFrame * CFrame.new(lCONTROL.L + lCONTROL.R, (lCONTROL.F + lCONTROL.B + CONTROL.Q + CONTROL.E) * 0.2, 0).p) - camera.CFrame.p)) * SPEED
			else
				BV.Velocity = Vector3.new(0, 0, 0)
			end
			BG.CFrame = camera.CFrame
		until not FLYING
		
		CONTROL = {F = 0, B = 0, L = 0, R = 0, Q = 0, E = 0}
		lCONTROL = {F = 0, B = 0, L = 0, R = 0, Q = 0, E = 0}
		SPEED = 0
		BG:Destroy()
		BV:Destroy()
		if char:FindFirstChildWhichIsA("Humanoid") then
			char:FindFirstChildWhichIsA("Humanoid").PlatformStand = false
		end
	end)
end

-- 텔레포트 핵심 로직
local function teleportToPlayer(targetName)
	local targetPlayer = Players:FindFirstChild(targetName)
	if not targetPlayer or targetPlayer == LocalPlayer then return end
	
	local targetChar = targetPlayer.Character
	local myChar = LocalPlayer.Character
	
	if targetChar and myChar then
		local targetHumanoid = targetChar:FindFirstChildWhichIsA("Humanoid")
		local myRoot = getRoot(myChar)
		local targetRoot = getRoot(targetChar)
		
		if targetHumanoid and targetHumanoid.Health > 0 and myRoot and targetRoot then
			myRoot.CFrame = targetRoot.CFrame * CFrame.new(0, 5, 0)
		end
	end
end

-- ==========================================
-- 5. ESP 드로잉 로직 및 오브젝트 관리
-- ==========================================
local function createESP(player)
	local char = player.Character
	if not char then return end
	
	-- 형광 아웃라인(Highlight) 생성
	if not char:FindFirstChild("ESP_Highlight") then
		local highlight = Instance.new("Highlight")
		highlight.Name = "ESP_Highlight"
		highlight.FillColor = Color3.fromRGB(57, 255, 20)
		highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
		highlight.FillTransparency = 0.5
		highlight.Parent = char
	end
	
	-- 머리 위 UI(Name & Health) 생성
	local head = char:FindFirstChild("Head") or char:FindFirstChild("UpperTorso")
	if head and not head:FindFirstChild("ESP_UI") then
		local billboard = Instance.new("BillboardGui")
		billboard.Name = "ESP_UI"
		billboard.Size = UDim2.new(0, 100, 0, 50)
		billboard.StudsOffset = Vector3.new(0, 2, 0)
		billboard.AlwaysOnTop = true
		billboard.Parent = head
		
		local nameLabel = Instance.new("TextLabel", billboard)
		nameLabel.Size = UDim2.new(1, 0, 0.5, 0)
		nameLabel.BackgroundTransparency = 1
		nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
		nameLabel.TextStrokeTransparency = 0
		nameLabel.Text = player.DisplayName or player.Name
		nameLabel.TextSize = 10
		
		local healthBar = Instance.new("Frame", billboard)
		healthBar.Size = UDim2.new(1, 0, 0.15, 0)
		healthBar.Position = UDim2.new(0, 0, 0.6, 0)
		healthBar.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
		healthBar.BorderSizePixel = 0
		
		local healthFill = Instance.new("Frame", healthBar)
		healthFill.Size = UDim2.new(1, 0, 1, 0)
		healthFill.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
		healthFill.BorderSizePixel = 0
		healthFill.Name = "HealthFill"
	end
end

local function clearESP(player)
	if player.Character then
		for _, v in pairs(player.Character:GetDescendants()) do
			if v.Name == "ESP_Highlight" or v.Name == "ESP_UI" then 
				v:Destroy() 
			end
		end
	end
end

-- ==========================================
-- 6. 에임봇 타겟 연산 및 장애물 판정
-- ==========================================
local function IsValidTarget(character)
    if not character or not character:FindFirstChild("HumanoidRootPart") then return false end
    local humanoid = character:FindFirstChild("Humanoid")
    if not humanoid or humanoid.Health <= 0 then return false end

    -- Raycast 벽 투과 감지
    local RayParams = RaycastParams.new()
    RayParams.FilterDescendantsInstances = {LocalPlayer.Character, character}
    RayParams.FilterType = Enum.RaycastFilterType.Exclude
    local RayRes = workspace:Raycast(Camera.CFrame.Position, (character.HumanoidRootPart.Position - Camera.CFrame.Position).Unit * 500, RayParams)
    
    return not RayRes -- 레이가 가로막히지 않았을 때 유효
end

local function GetClosestTarget()
    local Closest = nil
    local MinDist = FovRadius
    local Center = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)

    for _, v in pairs(Players:GetPlayers()) do
        if v ~= LocalPlayer and v.Character then
            if IsValidTarget(v.Character) then
                local Pos, OnScreen = Camera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
                local Dist = (Vector2.new(Pos.X, Pos.Y) - Center).Magnitude
                
                if OnScreen and Dist < MinDist then
                    MinDist = Dist
                    Closest = v.Character.HumanoidRootPart
                end
            end
        end
    end
    return Closest
end

-- ==========================================
-- 7. 입력 제어 핸들러 (PC & 마우스 조작 설정)
-- ==========================================
if not IsMobile then
    UserInputService.InputBegan:Connect(function(input, processed)
        if processed then return end
        if input.UserInputType == Enum.UserInputType.MouseButton2 then
            IsRightMouseDown = true
        elseif input.KeyCode == Enum.KeyCode.R then
            IsRKeyDown = true
        end
    end)

    UserInputService.InputEnded:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton2 then
            IsRightMouseDown = false
            LockedTarget = nil
        elseif input.KeyCode == Enum.KeyCode.R then
            IsRKeyDown = false
            LockedTarget = nil
        end
    end)
end

-- 마우스 휠로 FOV 변경
UserInputService.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseWheel then
        FovRadius = math.clamp(FovRadius + (input.Position.Z * 10), 10, 500)
    end
end)

-- ==========================================
-- 8. 통합 시스템 루프 (Heartbeat / RenderStepped)
-- ==========================================

-- Noclip 루프 (물리 관여 단계)
RunService.Stepped:Connect(function()
	if NOCLIP and LocalPlayer.Character then
		for _, part in pairs(LocalPlayer.Character:GetDescendants()) do
			if part:IsA("BasePart") and part.CanCollide then
				part.CanCollide = false
			end
		end
	end
end)

-- WalkSpeed 고정 루프
task.spawn(function()
	while true do
		task.wait(0.1)
		local char = LocalPlayer.Character
		if char then
			local humanoid = char:FindFirstChildWhichIsA("Humanoid")
			if humanoid and not FLYING then
				humanoid.WalkSpeed = walkspeed_val
			end
		end
	end
end)

-- 모바일용 가상 조이스틱 플라이 연동 루프
task.spawn(function()
	while true do
		task.wait()
		local char = LocalPlayer.Character
		if char then
			local humanoid = char:FindFirstChildWhichIsA("Humanoid")
			if humanoid and FLYING then
				local moveDir = humanoid.MoveDirection
				if moveDir.Magnitude > 0 then
					local camera = workspace.CurrentCamera
					local look = camera.CFrame.LookVector
					local right = camera.CFrame.RightVector
					
					local forwardDot = moveDir:Dot(Vector3.new(look.X, 0, look.Z).Unit)
					local rightDot = moveDir:Dot(Vector3.new(right.X, 0, right.Z).Unit)
					
					CONTROL.F = forwardDot
					CONTROL.B = 0
					CONTROL.L = rightDot
					CONTROL.R = 0
				else
					CONTROL.F = 0
					CONTROL.B = 0
					CONTROL.L = 0
					CONTROL.R = 0
				end
			end
		end
	end
end)

-- [렌더 루프 통일]: ESP, 에임봇, 오토샷 동시 처리
RunService.RenderStepped:Connect(function()
	-- 1. ESP 동작부
	if ESP_ENABLED then
		for _, p in pairs(Players:GetPlayers()) do
			if p ~= LocalPlayer and p.Character then
				local humanoid = p.Character:FindFirstChildWhichIsA("Humanoid")
				if humanoid and humanoid.Health > 0 then
					createESP(p)
					-- 헬스바 실시간 업데이트
					local head = p.Character:FindFirstChild("Head") or p.Character:FindFirstChild("UpperTorso")
					if head and head:FindFirstChild("ESP_UI") then
						local fill = head.ESP_UI:FindFirstChild("Frame"):FindFirstChild("HealthFill")
						fill.Size = UDim2.new(math.clamp(humanoid.Health / humanoid.MaxHealth, 0, 1), 0, 1, 0)
					end
				else
					clearESP(p)
				end
			end
		end
	else
		for _, p in pairs(Players:GetPlayers()) do 
			clearESP(p) 
		end
	end

	-- 2. 에임봇 동작부 & FOV 원 그리기
	if AimEnabled then
		FovCircle.Position = Vector2.new(Camera.ViewportSize.X/2, Camera.ViewportSize.Y/2)
		FovCircle.Radius = FovRadius
		FovCircle.Visible = true

		local ShouldAim = false
		if IsMobile then
			ShouldAim = true
		else
			ShouldAim = IsRightMouseDown or IsRKeyDown
		end

		if ShouldAim then
			if not IsMobile and LockedTarget then
				if IsValidTarget(LockedTarget.Parent) then
					Camera.CFrame = CFrame.new(Camera.CFrame.Position, LockedTarget.Position)
				else
					LockedTarget = nil
				end
			end

			if not LockedTarget then
				local NewTarget = GetClosestTarget()
				if NewTarget then
					if not IsMobile then
						LockedTarget = NewTarget
					end
					Camera.CFrame = CFrame.new(Camera.CFrame.Position, NewTarget.Position)
				end
			end
		else
			LockedTarget = nil
		end
	else
		FovCircle.Visible = false
		LockedTarget = nil
	end

	-- 3. 오토샷 동작부
	if AutoShotEnabled and Mouse.Target then
		local Hit = Mouse.Target:FindFirstAncestorOfClass("Model")
		if Hit and Hit:FindFirstChild("Humanoid") and Hit.Humanoid.Health > 0 and Hit ~= LocalPlayer.Character then
			local RayParams = RaycastParams.new()
			RayParams.FilterDescendantsInstances = {LocalPlayer.Character, Hit}
			RayParams.FilterType = Enum.RaycastFilterType.Exclude
			local RayRes = workspace:Raycast(Camera.CFrame.Position, (Mouse.Hit.Position - Camera.CFrame.Position).Unit * 500, RayParams)
			
			if not RayRes then
				mouse1click()
			end
		end
	end
end)

-- ==========================================
-- 9. 통합 GUI 레이아웃 빌드
-- ==========================================
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "IY_Utility_Hub_V3"
ScreenGui.ResetOnSpawn = false
local success, parent = pcall(function() return CoreGui end)
ScreenGui.Parent = success and parent or LocalPlayer:WaitForChild("PlayerGui")

local Frame = Instance.new("Frame")
Frame.Size = UDim2.new(0, 240, 0, 360) -- 에임봇 요소 수용을 위해 세로 크기 360으로 증가
Frame.Position = UDim2.new(1, -260, 0.5, -180)
Frame.BackgroundColor3 = Color3.fromRGB(25, 25, 25)
Frame.BorderSizePixel = 0
Frame.Active = true
Frame.Draggable = true
Frame.Parent = ScreenGui

local UICorner = Instance.new("UICorner")
UICorner.CornerRadius = UDim.new(0, 10)
UICorner.Parent = Frame

-- [탭 구성]
local TabHeader = Instance.new("Frame")
TabHeader.Size = UDim2.new(1, 0, 0, 35)
TabHeader.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
TabHeader.BorderSizePixel = 0
TabHeader.Parent = Frame

local HeaderCorner = Instance.new("UICorner")
HeaderCorner.CornerRadius = UDim.new(0, 10)
HeaderCorner.Parent = TabHeader

local HeaderLine = Instance.new("Frame")
HeaderLine.Size = UDim2.new(1, 0, 0, 5)
HeaderLine.Position = UDim2.new(0, 0, 1, -5)
HeaderLine.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
HeaderLine.BorderSizePixel = 0
HeaderLine.Parent = TabHeader

local MainTabBtn = Instance.new("TextButton")
MainTabBtn.Size = UDim2.new(0.5, 0, 1, 0)
MainTabBtn.BackgroundTransparency = 1
MainTabBtn.Text = "Main"
MainTabBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
MainTabBtn.TextSize = 14
MainTabBtn.Font = Enum.Font.SourceSansBold
MainTabBtn.Parent = TabHeader

local PlayerTabBtn = Instance.new("TextButton")
PlayerTabBtn.Size = UDim2.new(0.5, 0, 1, 0)
PlayerTabBtn.Position = UDim2.new(0.5, 0, 0, 0)
PlayerTabBtn.BackgroundTransparency = 1
PlayerTabBtn.Text = "Player & Combat"
PlayerTabBtn.TextColor3 = Color3.fromRGB(150, 150, 150)
PlayerTabBtn.TextSize = 14
PlayerTabBtn.Font = Enum.Font.SourceSansBold
PlayerTabBtn.Parent = TabHeader

-- [메인 탭 프레임]
local MainTabFrame = Instance.new("Frame")
MainTabFrame.Size = UDim2.new(1, 0, 1, -35)
MainTabFrame.Position = UDim2.new(0, 0, 0, 35)
MainTabFrame.BackgroundTransparency = 1
MainTabFrame.Visible = true
MainTabFrame.Parent = Frame

-- [플레이어 탭 프레임 (세로 스크롤 허용으로 깔끔한 레이아웃 구성)]
local PlayerTabFrame = Instance.new("ScrollingFrame")
PlayerTabFrame.Size = UDim2.new(1, 0, 1, -35)
PlayerTabFrame.Position = UDim2.new(0, 0, 0, 35)
PlayerTabFrame.BackgroundTransparency = 1
PlayerTabFrame.BorderSizePixel = 0
PlayerTabFrame.ScrollBarThickness = 5
PlayerTabFrame.CanvasSize = UDim2.new(0, 0, 0, 420) -- 구성 요소 확장에 따른 캔버스 크기 지정
PlayerTabFrame.Visible = false
PlayerTabFrame.Parent = Frame

-- 탭 변환 이벤트
MainTabBtn.MouseButton1Click:Connect(function()
	MainTabFrame.Visible = true
	PlayerTabFrame.Visible = false
	MainTabBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
	PlayerTabBtn.TextColor3 = Color3.fromRGB(150, 150, 150)
end)

PlayerTabBtn.MouseButton1Click:Connect(function()
	MainTabFrame.Visible = false
	PlayerTabFrame.Visible = true
	MainTabBtn.TextColor3 = Color3.fromRGB(150, 150, 150)
	PlayerTabBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
end)

-- ==========================================
-- 10. Main 탭 컴포넌트 렌더링
-- ==========================================
local FlyBtn = Instance.new("TextButton")
FlyBtn.Size = UDim2.new(0, 100, 0, 35)
FlyBtn.Position = UDim2.new(0, 15, 0, 15)
FlyBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
FlyBtn.Text = "Fly: OFF"
FlyBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
FlyBtn.TextSize = 14
FlyBtn.Font = Enum.Font.SourceSansSemibold
FlyBtn.Parent = MainTabFrame

local FlyBtnCorner = Instance.new("UICorner")
FlyBtnCorner.CornerRadius = UDim.new(0, 6)
FlyBtnCorner.Parent = FlyBtn

FlyBtn.MouseButton1Click:Connect(function()
	if FLYING then
		NOFLY()
		FlyBtn.Text = "Fly: OFF"
		FlyBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
	else
		sFLY()
		FlyBtn.Text = "Fly: ON"
		FlyBtn.BackgroundColor3 = Color3.fromRGB(0, 180, 100)
	end
end)

local NoclipBtn = Instance.new("TextButton")
NoclipBtn.Size = UDim2.new(0, 100, 0, 35)
NoclipBtn.Position = UDim2.new(0, 125, 0, 15)
NoclipBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
NoclipBtn.Text = "Noclip: OFF"
NoclipBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
NoclipBtn.TextSize = 14
NoclipBtn.Font = Enum.Font.SourceSansSemibold
NoclipBtn.Parent = MainTabFrame

local NoclipBtnCorner = Instance.new("UICorner")
NoclipBtnCorner.CornerRadius = UDim.new(0, 6)
NoclipBtnCorner.Parent = NoclipBtn

NoclipBtn.MouseButton1Click:Connect(function()
	NOCLIP = not NOCLIP
	if NOCLIP then
		NoclipBtn.Text = "Noclip: ON"
		NoclipBtn.BackgroundColor3 = Color3.fromRGB(0, 180, 100)
	else
		NoclipBtn.Text = "Noclip: OFF"
		NoclipBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
	end
end)

local FlyLabel = Instance.new("TextLabel")
FlyLabel.Size = UDim2.new(1, -30, 0, 20)
FlyLabel.Position = UDim2.new(0, 15, 0, 65)
FlyLabel.Text = "Fly Speed: 1.0x"
FlyLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
FlyLabel.TextSize = 13
FlyLabel.TextXAlignment = Enum.TextXAlignment.Left
FlyLabel.BackgroundTransparency = 1
FlyLabel.Parent = MainTabFrame

local FlySliderBg = Instance.new("Frame")
FlySliderBg.Size = UDim2.new(1, -30, 0, 10)
FlySliderBg.Position = UDim2.new(0, 15, 0, 90)
FlySliderBg.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
FlySliderBg.BorderSizePixel = 0
FlySliderBg.Parent = MainTabFrame

local FlySliderBar = Instance.new("Frame")
FlySliderBar.Size = UDim2.new(0.1, 0, 1, 0)
FlySliderBar.BackgroundColor3 = Color3.fromRGB(0, 150, 255)
FlySliderBar.BorderSizePixel = 0
FlySliderBar.Parent = FlySliderBg

local function UpdateFlySpeed(input)
	local percentage = math.clamp((input.Position.X - FlySliderBg.AbsolutePosition.X) / FlySliderBg.AbsoluteSize.X, 0, 1)
	FlySliderBar.Size = UDim2.new(percentage, 0, 1, 0)
	iyflyspeed = math.round((0.1 + (percentage * 9.9)) * 10) / 10
	FlyLabel.Text = "Fly Speed: " .. string.format("%.1f", iyflyspeed) .. "x"
end

local draggingFly = false
FlySliderBg.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		draggingFly = true
		UpdateFlySpeed(input)
	end
end)

UserInputService.InputChanged:Connect(function(input)
	if draggingFly and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
		UpdateFlySpeed(input)
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		draggingFly = false
	end
end)

local WalkLabel = Instance.new("TextLabel")
WalkLabel.Size = UDim2.new(1, -30, 0, 20)
WalkLabel.Position = UDim2.new(0, 15, 0, 120)
WalkLabel.Text = "WalkSpeed: 16"
WalkLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
WalkLabel.TextSize = 13
WalkLabel.TextXAlignment = Enum.TextXAlignment.Left
WalkLabel.BackgroundTransparency = 1
WalkLabel.Parent = MainTabFrame

local WalkSliderBg = Instance.new("Frame")
WalkSliderBg.Size = UDim2.new(1, -30, 0, 10)
WalkSliderBg.Position = UDim2.new(0, 15, 0, 145)
WalkSliderBg.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
WalkSliderBg.BorderSizePixel = 0
WalkSliderBg.Parent = MainTabFrame

local WalkSliderBar = Instance.new("Frame")
WalkSliderBar.Size = UDim2.new(0.08, 0, 1, 0)
WalkSliderBar.BackgroundColor3 = Color3.fromRGB(255, 170, 0)
WalkSliderBar.BorderSizePixel = 0
WalkSliderBar.Parent = WalkSliderBg

local function UpdateWalkSpeed(input)
	local percentage = math.clamp((input.Position.X - WalkSliderBg.AbsolutePosition.X) / WalkSliderBg.AbsoluteSize.X, 0, 1)
	WalkSliderBar.Size = UDim2.new(percentage, 0, 1, 0)
	walkspeed_val = math.round(16 + (percentage * 184))
	WalkLabel.Text = "WalkSpeed: " .. tostring(walkspeed_val)
	
	local char = LocalPlayer.Character
	if char then
		local humanoid = char:FindFirstChildWhichIsA("Humanoid")
		if humanoid and not FLYING then
			humanoid.WalkSpeed = walkspeed_val
		end
	end
end

local draggingWalk = false
WalkSliderBg.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		draggingWalk = true
		UpdateWalkSpeed(input)
	end
end)

UserInputService.InputChanged:Connect(function(input)
	if draggingWalk and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
		UpdateWalkSpeed(input)
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		draggingWalk = false
	end
end)

-- ==========================================
-- 11. Player & Combat 탭 컴포넌트 렌더링
-- ==========================================
local DropdownLabel = Instance.new("TextLabel")
DropdownLabel.Size = UDim2.new(1, -30, 0, 20)
DropdownLabel.Position = UDim2.new(0, 15, 0, 10)
DropdownLabel.Text = "Select Target Player:"
DropdownLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
DropdownLabel.TextSize = 13
DropdownLabel.TextXAlignment = Enum.TextXAlignment.Left
DropdownLabel.BackgroundTransparency = 1
DropdownLabel.Parent = PlayerTabFrame

local DropdownBtn = Instance.new("TextButton")
DropdownBtn.Size = UDim2.new(1, -30, 0, 30)
DropdownBtn.Position = UDim2.new(0, 15, 0, 35)
DropdownBtn.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
DropdownBtn.Text = "--- Select ---"
DropdownBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
DropdownBtn.TextSize = 13
DropdownBtn.Font = Enum.Font.SourceSans
DropdownBtn.Parent = PlayerTabFrame

local DropdownBtnCorner = Instance.new("UICorner")
DropdownBtnCorner.CornerRadius = UDim.new(0, 4)
DropdownBtnCorner.Parent = DropdownBtn

local DropdownList = Instance.new("ScrollingFrame")
DropdownList.Size = UDim2.new(1, -30, 0, 100)
DropdownList.Position = UDim2.new(0, 15, 0, 70)
DropdownList.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
DropdownList.BorderSizePixel = 0
DropdownList.Visible = false
DropdownList.ZIndex = 5
DropdownList.CanvasSize = UDim2.new(0, 0, 0, 0)
DropdownList.ScrollBarThickness = 6
DropdownList.Parent = PlayerTabFrame

local ListLayout = Instance.new("UIListLayout")
ListLayout.Parent = DropdownList
ListLayout.SortOrder = Enum.SortOrder.LayoutOrder

DropdownBtn.MouseButton1Click:Connect(function()
	DropdownList.Visible = not DropdownList.Visible
end)

-- TP Once 버튼
local OnceTpBtn = Instance.new("TextButton")
OnceTpBtn.Size = UDim2.new(0, 100, 0, 35)
OnceTpBtn.Position = UDim2.new(0, 15, 0, 185)
OnceTpBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
OnceTpBtn.Text = "TP Once"
OnceTpBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
OnceTpBtn.TextSize = 14
OnceTpBtn.Font = Enum.Font.SourceSansSemibold
OnceTpBtn.Parent = PlayerTabFrame

local OnceTpBtnCorner = Instance.new("UICorner")
OnceTpBtnCorner.CornerRadius = UDim.new(0, 6)
OnceTpBtnCorner.Parent = OnceTpBtn

OnceTpBtn.MouseButton1Click:Connect(function()
	if targetPlayerName ~= "" and targetPlayerName ~= "--- Select ---" then
		teleportToPlayer(targetPlayerName)
	end
end)

-- Loop TP 버튼
local LoopTpBtn = Instance.new("TextButton")
LoopTpBtn.Size = UDim2.new(0, 100, 0, 35)
LoopTpBtn.Position = UDim2.new(0, 125, 0, 185)
LoopTpBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
LoopTpBtn.Text = "Loop TP: OFF"
LoopTpBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
LoopTpBtn.TextSize = 14
LoopTpBtn.Font = Enum.Font.SourceSansSemibold
LoopTpBtn.Parent = PlayerTabFrame

local LoopTpBtnCorner = Instance.new("UICorner")
LoopTpBtnCorner.CornerRadius = UDim.new(0, 6)
LoopTpBtnCorner.Parent = LoopTpBtn

local function startLoopTp()
	loopTeleportActive = true
	LoopTpBtn.Text = "Loop TP: ON"
	LoopTpBtn.BackgroundColor3 = Color3.fromRGB(0, 180, 100)
	
	loopTeleportConn = RunService.Heartbeat:Connect(function()
		if loopTeleportActive and targetPlayerName ~= "" then
			teleportToPlayer(targetPlayerName)
		end
	end)
end

local function stopLoopTp()
	loopTeleportActive = false
	LoopTpBtn.Text = "Loop TP: OFF"
	LoopTpBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
	if loopTeleportConn then
		loopTeleportConn:Disconnect()
		loopTeleportConn = nil
	end
end

LoopTpBtn.MouseButton1Click:Connect(function()
	if loopTeleportActive then
		stopLoopTp()
	else
		if targetPlayerName ~= "" and targetPlayerName ~= "--- Select ---" then
			startLoopTp()
		end
	end
end)

-- ESP 토글 버튼
local EspBtn = Instance.new("TextButton")
EspBtn.Size = UDim2.new(0, 100, 0, 35)
EspBtn.Position = UDim2.new(0, 15, 0, 235)
EspBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
EspBtn.Text = "ESP: OFF"
EspBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
EspBtn.TextSize = 14
EspBtn.Font = Enum.Font.SourceSansSemibold
EspBtn.Parent = PlayerTabFrame

local EspBtnCorner = Instance.new("UICorner")
EspBtnCorner.CornerRadius = UDim.new(0, 6)
EspBtnCorner.Parent = EspBtn

EspBtn.MouseButton1Click:Connect(function()
	ESP_ENABLED = not ESP_ENABLED
	EspBtn.Text = ESP_ENABLED and "ESP: ON" or "ESP: OFF"
	EspBtn.BackgroundColor3 = ESP_ENABLED and Color3.fromRGB(0, 180, 100) or Color3.fromRGB(60, 60, 60)
end)

-- Aimbot 토글 버튼
local AimBtn = Instance.new("TextButton")
AimBtn.Size = UDim2.new(0, 100, 0, 35)
AimBtn.Position = UDim2.new(0, 125, 0, 235)
AimBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
AimBtn.Text = "Aimbot: OFF"
AimBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
AimBtn.TextSize = 14
AimBtn.Font = Enum.Font.SourceSansSemibold
AimBtn.Parent = PlayerTabFrame

local AimBtnCorner = Instance.new("UICorner")
AimBtnCorner.CornerRadius = UDim.new(0, 6)
AimBtnCorner.Parent = AimBtn

AimBtn.MouseButton1Click:Connect(function()
	AimEnabled = not AimEnabled
	AimBtn.Text = AimEnabled and "Aimbot: ON" or "Aimbot: OFF"
	AimBtn.BackgroundColor3 = AimEnabled and Color3.fromRGB(0, 180, 100) or Color3.fromRGB(60, 60, 60)
end)

-- AutoShot 토글 버튼
local AutoShotBtn = Instance.new("TextButton")
AutoShotBtn.Size = UDim2.new(0, 100, 0, 35)
AutoShotBtn.Position = UDim2.new(0, 15, 0, 285)
AutoShotBtn.BackgroundColor3 = Color3.fromRGB(60, 60, 60)
AutoShotBtn.Text = "AutoShot: OFF"
AutoShotBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
AutoShotBtn.TextSize = 14
AutoShotBtn.Font = Enum.Font.SourceSansSemibold
AutoShotBtn.Parent = PlayerTabFrame

local AutoShotBtnCorner = Instance.new("UICorner")
AutoShotBtnCorner.CornerRadius = UDim.new(0, 6)
AutoShotBtnCorner.Parent = AutoShotBtn

AutoShotBtn.MouseButton1Click:Connect(function()
	AutoShotEnabled = not AutoShotEnabled
	AutoShotBtn.Text = AutoShotEnabled and "AutoShot: ON" or "AutoShot: OFF"
	AutoShotBtn.BackgroundColor3 = AutoShotEnabled and Color3.fromRGB(0, 180, 100) or Color3.fromRGB(60, 60, 60)
end)

-- Aimbot FOV 설정 슬라이더
local FovLabel = Instance.new("TextLabel")
FovLabel.Size = UDim2.new(1, -30, 0, 20)
FovLabel.Position = UDim2.new(0, 15, 0, 335)
FovLabel.Text = "Aimbot FOV: 100"
FovLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
FovLabel.TextSize = 13
FovLabel.TextXAlignment = Enum.TextXAlignment.Left
FovLabel.BackgroundTransparency = 1
FovLabel.Parent = PlayerTabFrame

local FovSliderBg = Instance.new("Frame")
FovSliderBg.Size = UDim2.new(1, -30, 0, 10)
FovSliderBg.Position = UDim2.new(0, 15, 0, 360)
FovSliderBg.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
FovSliderBg.BorderSizePixel = 0
FovSliderBg.Parent = PlayerTabFrame

local FovSliderBar = Instance.new("Frame")
FovSliderBar.Size = UDim2.new(0.2, 0, 1, 0) -- 100/500 = 0.2
FovSliderBar.BackgroundColor3 = Color3.fromRGB(180, 50, 255)
FovSliderBar.BorderSizePixel = 0
FovSliderBar.Parent = FovSliderBg

local function UpdateFovValue(input)
	local percentage = math.clamp((input.Position.X - FovSliderBg.AbsolutePosition.X) / FovSliderBg.AbsoluteSize.X, 0, 1)
	FovSliderBar.Size = UDim2.new(percentage, 0, 1, 0)
	FovRadius = math.round(10 + (percentage * 490))
	FovLabel.Text = "Aimbot FOV: " .. tostring(FovRadius)
end

local draggingFov = false
FovSliderBg.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		draggingFov = true
		UpdateFovValue(input)
	end
end)

UserInputService.InputChanged:Connect(function(input)
	if draggingFov and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
		UpdateFovValue(input)
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
		draggingFov = false
	end
end)

-- ==========================================
-- 12. 유저 드롭다운 동적 리프레시 시스템
-- ==========================================
local function rebuildDropdown()
	for _, child in ipairs(DropdownList:GetChildren()) do
		if child:IsA("TextButton") then
			child:Destroy()
		end
	end
	
	local validPlayers = {}
	for _, p in ipairs(Players:GetPlayers()) do
		if p ~= LocalPlayer then
			table.insert(validPlayers, p)
		end
	end
	
	local itemHeight = 25
	DropdownList.CanvasSize = UDim2.new(0, 0, 0, #validPlayers * itemHeight)
	
	for _, p in ipairs(validPlayers) do
		local pBtn = Instance.new("TextButton")
		pBtn.Size = UDim2.new(1, 0, 0, itemHeight)
		pBtn.BackgroundTransparency = 1
		pBtn.Text = p.DisplayName .. " (@" .. p.Name .. ")"
		pBtn.TextColor3 = Color3.fromRGB(200, 200, 200)
		pBtn.TextSize = 12
		pBtn.Font = Enum.Font.SourceSans
		pBtn.Parent = DropdownList
		
		pBtn.MouseButton1Click:Connect(function()
			targetPlayerName = p.Name
			DropdownBtn.Text = p.DisplayName
			DropdownList.Visible = false
		end)
	end
	
	if targetPlayerName ~= "" and not Players:FindFirstChild(targetPlayerName) then
		targetPlayerName = ""
		DropdownBtn.Text = "--- Select ---"
		if loopTeleportActive then
			stopLoopTp()
		end
	end
end

Players.PlayerAdded:Connect(rebuildDropdown)
Players.PlayerRemoving:Connect(rebuildDropdown)
rebuildDropdown()

-- ==========================================
-- 13. 캐릭터 리스폰 유지 시스템
-- ==========================================
LocalPlayer.CharacterAdded:Connect(function(newCharacter)
	newCharacter:WaitForChild("Humanoid")
	task.wait(0.5)
	
	if FLYING then
		sFLY()
	else
		local humanoid = newCharacter:FindFirstChildWhichIsA("Humanoid")
		if humanoid then
			humanoid.WalkSpeed = walkspeed_val
		end
	end
end)

if LocalPlayer.Character then
	local humanoid = LocalPlayer.Character:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = walkspeed_val
	end
	if FLYING then
		task.spawn(sFLY)
	end
end

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: