Certainly! Below is the enhanced Roblox Lua script that incorporates a draggable and hiddable GUI for selecting which humanoid part to target (left arm, right arm, torso, head, left leg, right leg). The script accommodates both R6 and R15 rigs, ensuring dynamic targeting based on the selected part.
Features Added:
- Draggable and Hiddable GUI: A user interface that can be moved around the screen and toggled visible/hidden using the
T key.
- Part Selection: Allows the user to select which humanoid part to target from a dropdown menu.
- Dynamic Targeting: Depending on whether the character uses an R6 or R15 rig, the script dynamically targets the selected part.
- Enhanced ESP: The ESP indicator now reflects the targeted part instead of being limited to the head.
Full Enhanced Script:
-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local GuiService = game:GetService("GuiService")
-- Configuration
local ROTATION_SPEED = 1.1 -- Speed of the rotation interpolation
local ESP_TEXT_PREFIX = "Targeted:" -- Prefix Text displayed in ESP
local ESP_COLOR = Color3.fromRGB(255, 0, 0) -- Color of the ESP text
local GUI_TOGGLE_KEY = Enum.KeyCode.T -- Key to toggle the GUI visibility
-- Variables
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local trackedTarget = nil -- Currently tracked target (another player)
local espIndicator = nil -- BillboardGui for ESP
local selectedPart = "HumanoidRootPart" -- Default targeted part
local guiVisible = true
-- List of possible target parts
local targetPartsListR6 = {
"Left Arm",
"Right Arm",
"Torso",
"Head",
"Left Leg",
"Right Leg"
}
local targetPartsListR15 = {
"LeftUpperArm",
"RightUpperArm",
"UpperTorso",
"Head",
"LeftUpperLeg",
"RightUpperLeg"
}
-- Determine if the character is R6 or R15
local isR15 = character:WaitForChild("Humanoid"):GetRigType() == Enum.HumanoidRigType.R15
local targetPartsList = isR15 and targetPartsListR15 or targetPartsListR6
-- Helper Function: Check if a model has a Humanoid
local function hasHumanoid(model)
return model and model:FindFirstChildOfClass("Humanoid") ~= nil
end
-- Helper Function: Find the closest player to the local player
local function findClosestPlayer()
local closestPlayer = nil
local shortestDistance = math.huge
for _, otherPlayer in ipairs(Players:GetPlayers()) do
if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
local distance = (otherPlayer.Character.HumanoidRootPart.Position - humanoidRootPart.Position).Magnitude
if distance < shortestDistance then
shortestDistance = distance
closestPlayer = otherPlayer
end
end
end
return closestPlayer
end
-- Function: Toggle Lock-On to the Closest Player when E is pressed
local function toggleLockOn()
if trackedTarget then
-- Deselect the current target
trackedTarget = nil
if espIndicator then
espIndicator:Destroy()
espIndicator = nil
end
else
-- Find and select the closest player
local closestPlayer = findClosestPlayer()
if closestPlayer and closestPlayer.Character then
trackedTarget = closestPlayer.Character
-- Create ESP indicator
local targetPartName = selectedPart
local targetPart = trackedTarget:FindFirstChild(targetPartName)
if not targetPart and isR15 then
-- For R15, parts might have different naming conventions
targetPart = trackedTarget:FindFirstChild(targetPartName)
elseif not targetPart then
-- For R6, some parts might have different names
targetPart = trackedTarget:FindFirstChild(targetPartName)
end
if targetPart then
-- Ensure previous ESP is removed
if espIndicator then
espIndicator:Destroy()
espIndicator = nil
end
-- Create BillboardGui for ESP
espIndicator = Instance.new("BillboardGui")
espIndicator.Adornee = targetPart
espIndicator.Size = UDim2.new(0, 100, 0, 50)
espIndicator.StudsOffset = Vector3.new(0, 2, 0)
espIndicator.AlwaysOnTop = true
espIndicator.Name = "TargetESP"
-- Create TextLabel for ESP
local textLabel = Instance.new("TextLabel")
textLabel.Parent = espIndicator
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.BackgroundTransparency = 1
textLabel.Text = ESP_TEXT_PREFIX .. " " .. targetPartName
textLabel.TextColor3 = ESP_COLOR
textLabel.Font = Enum.Font.SourceSansBold
textLabel.TextScaled = true
textLabel.TextStrokeTransparency = 0.8
-- Parent the ESP to the player's PlayerGui
espIndicator.Parent = player:WaitForChild("PlayerGui")
end
end
end
end
-- Function: Smoothly rotate to face the tracked target
local function smoothRotateToTarget()
if trackedTarget then
local targetPart = trackedTarget:FindFirstChild(selectedPart)
if targetPart then
local targetPosition = Vector3.new(targetPart.Position.X, humanoidRootPart.Position.Y, targetPart.Position.Z)
local direction = (targetPosition - humanoidRootPart.Position).Unit
local desiredCFrame = CFrame.new(humanoidRootPart.Position, targetPosition)
-- Advanced Lerp for smooth 360° rotation
humanoidRootPart.CFrame = humanoidRootPart.CFrame:Lerp(desiredCFrame, ROTATION_SPEED * RunService.RenderStepped:Wait())
end
end
end
-- Function: Create Draggable and Hiddable GUI
local function createTargetSelectionGUI()
-- Create ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "TargetSelectionGUI"
screenGui.Parent = player:WaitForChild("PlayerGui")
screenGui.ResetOnSpawn = false
-- Create Main Frame
local mainFrame = Instance.new("Frame")
mainFrame.Name = "MainFrame"
mainFrame.Size = UDim2.new(0, 200, 0, 150)
mainFrame.Position = UDim2.new(0.5, -100, 0.1, 0)
mainFrame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
mainFrame.BorderSizePixel = 0
mainFrame.Active = true
mainFrame.Draggable = true -- Makes the frame draggable
mainFrame.Parent = screenGui
-- Create Title Bar
local titleBar = Instance.new("TextLabel")
titleBar.Name = "TitleBar"
titleBar.Size = UDim2.new(1, 0, 0, 30)
titleBar.Position = UDim2.new(0, 0, 0, 0)
titleBar.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
titleBar.BorderSizePixel = 0
titleBar.Text = "Target Selection"
titleBar.TextColor3 = Color3.fromRGB(255, 255, 255)
titleBar.TextScaled = true
titleBar.Font = Enum.Font.SourceSansBold
titleBar.Parent = mainFrame
-- Create Dropdown for Target Parts
local dropdown = Instance.new("Frame")
dropdown.Name = "Dropdown"
dropdown.Size = UDim2.new(0, 180, 0, 30)
dropdown.Position = UDim2.new(0, 10, 0, 40)
dropdown.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
dropdown.Parent = mainFrame
local dropdownLabel = Instance.new("TextLabel")
dropdownLabel.Name = "DropdownLabel"
dropdownLabel.Size = UDim2.new(1, 0, 1, 0)
dropdownLabel.Position = UDim2.new(0, 0, 0, 0)
dropdownLabel.BackgroundTransparency = 1
dropdownLabel.Text = "Select Part"
dropdownLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
dropdownLabel.TextScaled = true
dropdownLabel.Font = Enum.Font.SourceSans
dropdownLabel.Parent = dropdown
local dropdownButton = Instance.new("TextButton")
dropdownButton.Name = "DropdownButton"
dropdownButton.Size = UDim2.new(0, 20, 1, 0)
dropdownButton.Position = UDim2.new(1, -20, 0, 0)
dropdownButton.BackgroundTransparency = 1
dropdownButton.Text = "v"
dropdownButton.TextColor3 = Color3.fromRGB(255, 255, 255)
dropdownButton.Font = Enum.Font.SourceSans
dropdownButton.TextScaled = true
dropdownButton.Parent = dropdown
local dropdownList = Instance.new("Frame")
dropdownList.Name = "DropdownList"
dropdownList.Size = UDim2.new(0, 180, 0, 0)
dropdownList.Position = UDim2.new(0, 0, 0, 30)
dropdownList.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
dropdownList.Visible = false
dropdownList.ClipsDescendants = true
dropdownList.Parent = dropdown
local layout = Instance.new("UIListLayout")
layout.HorizontalAlignment = Enum.HorizontalAlignment.Left
layout.Parent = dropdownList
-- Populate Dropdown List
for _, partName in ipairs(targetPartsList) do
local option = Instance.new("TextButton")
option.Name = partName
option.Size = UDim2.new(1, 0, 0, 30)
option.BackgroundTransparency = 1
option.Text = partName
option.TextColor3 = Color3.fromRGB(255, 255, 255)
option.TextScaled = true
option.Font = Enum.Font.SourceSans
option.Parent = dropdownList
option.MouseButton1Click:Connect(function()
selectedPart = partName
dropdownLabel.Text = partName
dropdownList.Visible = false
end)
end
-- Toggle Dropdown List Visibility
dropdownButton.MouseButton1Click:Connect(function()
dropdownList.Visible = not dropdownList.Visible
end)
-- Close Dropdown if clicking outside
screenGui.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if not dropdown:IsAncestorOf(input.Target) then
dropdownList.Visible = false
end
end
end)
end
-- Function: Toggle GUI Visibility
local function toggleGUIVisibility()
guiVisible = not guiVisible
local gui = player:WaitForChild("PlayerGui"):FindFirstChild("TargetSelectionGUI")
if gui then
gui.Enabled = guiVisible
end
end
-- Event Listeners
-- Toggle Lock-On when E is pressed
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
if input.KeyCode == Enum.KeyCode.E then
toggleLockOn()
elseif input.KeyCode == GUI_TOGGLE_KEY then
toggleGUIVisibility()
end
end)
-- Handle character respawn
player.CharacterAdded:Connect(function(newCharacter)
character = newCharacter
humanoid = character:WaitForChild("Humanoid")
humanoidRootPart = character:WaitForChild("HumanoidRootPart")
-- Determine rig type again in case it changes
isR15 = humanoid:GetRigType() == Enum.HumanoidRigType.R15
targetPartsList = isR15 and targetPartsListR15 or targetPartsListR6
-- Reset tracking and ESP on respawn
trackedTarget = nil
if espIndicator then
espIndicator:Destroy()
espIndicator = nil
end
end)
-- Create the GUI on script start
createTargetSelectionGUI()
-- Render Step: Continuously update rotation if a target is tracked
RunService.RenderStepped:Connect(function()
if trackedTarget then
smoothRotateToTarget()
end
end)
Explanation of Enhancements:
-
GUI Creation (createTargetSelectionGUI Function):
- ScreenGui: A
ScreenGui named "TargetSelectionGUI" is created and parented to the player's PlayerGui.
- Main Frame: A draggable
Frame acts as the main container for the GUI elements.
- Title Bar: A
TextLabel serves as the title of the GUI.
- Dropdown Menu:
- The dropdown allows users to select the target part from a list.
- It dynamically populates the options based on whether the character is using R6 or R15.
- When an option is selected, it updates the
selectedPart variable and closes the dropdown.
- Draggability: The
Frame has Draggable set to true to enable moving the GUI around the screen.
-
GUI Visibility Toggle:
- The
T key is assigned to toggle the visibility of the GUI.
- When pressed, it either shows or hides the entire
TargetSelectionGUI.
-
Part Selection and Targeting:
- The
selectedPart variable holds the currently selected humanoid part to target.
- When lock-on is toggled (
E key), the script targets the closest player and focuses on the selectedPart instead of defaulting to the head.
- The ESP indicator updates to reflect the selected part's name.
-
Dynamic Rig Type Handling:
- The script checks if the character is using an R6 or R15 rig and adjusts the list of targetable parts accordingly.
- It also updates the part list upon character respawn in case the rig type changes.
-
Enhanced ESP Indicator:
- Instead of always pointing to the head, the ESP now points to the user-selected part (e.g., Left Arm, Right Leg).
- The ESP text includes the name of the targeted part for better clarity.
-
Smooth Rotation Adjustment:
- The
smoothRotateToTarget function ensures that the character smoothly rotates to face the targeted part, maintaining responsiveness even with dynamic movements of the target.
Usage Instructions:
-
Activating the GUI:
- Upon starting the game, the GUI will be visible by default.
- Press the
T key to hide or show the GUI as needed.
-
Selecting a Target Part:
- Click on the "Select Part" dropdown to view the list of available parts.
- Select the desired part (e.g., Head, Left Arm) to set it as the target.
- The dropdown will display the currently selected part.
-
Locking On to a Target:
- Press the
E key to lock on to the closest player.
- The ESP indicator will appear above the selected part of the target player.
- Press
E again to deselect the target.
-
Draggable GUI:
- Click and drag the main frame's title bar to move the GUI around the screen for your convenience.
Notes:
- Rig Compatibility: The script dynamically adjusts to both R6 and R15 rigs, ensuring compatibility across different avatars.
- ESP Limitations: Ensure that the target parts exist in the target character's model. Some custom avatars might have differently named parts, which could require further adjustments.
- Performance: The script leverages
RunService.RenderStepped for smooth rotation updates. Ensure that excessive use does not impact game performance, especially in large-scale games.
Feel free to customize the GUI appearance or add additional features as needed. This script provides a robust foundation for dynamic part targeting with an intuitive user interface.