Further enhance and add in an advanced post-movement tracking system with a more…
- User
Further enhance and add in an advanced post-movement tracking system with a more accurate and faster tracking.
-- Services local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local TweenService = game:GetService("TweenService") local Workspace = game:GetService("Workspace") local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Configuration local CONFIG = { ROTATION_DURATION = 0.05, -- Tween duration for rotation (0.05 seconds for near-instant rotation) ROTATION_EASING_STYLE = Enum.EasingStyle.Linear, -- Immediate, constant speed ROTATION_EASING_DIRECTION = Enum.EasingDirection.Out, ACTION_DISTANCE = 30, -- Maximum distance (in studs) to consider for actions MAX_TARGETS = 1, -- Maximum number of simultaneous targets ESP = { PlayerColor = Color3.fromRGB(0, 255, 0), NPCColor = Color3.fromRGB(0, 0, 255), Enabled = true, ToggleKey = Enum.KeyCode.E, -- Key to toggle ESP visibility }, NOTIFICATIONS = { Enabled = true, ToggleKey = Enum.KeyCode.T, -- Key to toggle notifications }, } -- Utility Functions local function createNotification(message) if not CONFIG.NOTIFICATIONS.Enabled then return end -- Implement a simple notification system -- You can expand this with better UI elements as needed print("[Notification]: " .. message) end local function toggleESPVisibility() CONFIG.ESP.Enabled = not CONFIG.ESP.Enabled createNotification("ESP Visibility: " .. (CONFIG.ESP.Enabled and "Enabled" or "Disabled")) -- Toggle visibility of all existing ESP indicators for _, billboard in pairs(ESP_INDICATORS) do if billboard and billboard.Parent then billboard.Enabled = CONFIG.ESP.Enabled end end end local function toggleNotifications() CONFIG.NOTIFICATIONS.Enabled = not CONFIG.NOTIFICATIONS.Enabled createNotification("Notifications: " .. (CONFIG.NOTIFICATIONS.Enabled and "Enabled" or "Disabled")) end -- Target Management local TARGET_MANAGER = {} TARGET_MANAGER.__index = TARGET_MANAGER function TARGET_MANAGER.new() local self = setmetatable({}, TARGET_MANAGER) self.trackedModels = {} self.espIndicators = {} return self end function TARGET_MANAGER:trackModel(model) if self.trackedModels[model] then return end -- Already tracked if #self:getTrackedModels() >= CONFIG.MAX_TARGETS then createNotification("Maximum number of targets reached.") return end self.trackedModels[model] = true self:createESP(model) createNotification("Tracked model: " .. (model.Name or "Unknown")) -- Connect to model's humanoid Died event local humanoid = model:FindFirstChildOfClass("Humanoid") if humanoid then humanoid.Died:Connect(function() self:untrackModel(model) end) end end function TARGET_MANAGER:untrackModel(model) if not self.trackedModels[model] then return end self.trackedModels[model] = nil self:removeESP(model) createNotification("Untracked model: " .. (model.Name or "Unknown")) end function TARGET_MANAGER:getTrackedModels() local models = {} for model, _ in pairs(self.trackedModels) do table.insert(models, model) end return models end function TARGET_MANAGER:createESP(model) if not CONFIG.ESP.Enabled then return end -- Ensure the model has a Head local head = model:FindFirstChild("Head") if not head then return end -- Create BillboardGui for ESP local billboard = Instance.new("BillboardGui") billboard.Name = "SimpleESP_" .. model.Name billboard.Adornee = head billboard.Size = UDim2.new(0, 100, 0, 30) billboard.StudsOffset = Vector3.new(0, 3, 0) billboard.AlwaysOnTop = true billboard.LightInfluence = 0 -- Ensure ESP is visible regardless of lighting billboard.Enabled = CONFIG.ESP.Enabled -- Text Label for ESP local textLabel = Instance.new("TextLabel") textLabel.Size = UDim2.new(1, 0, 1, 0) textLabel.Text = model.Name .. (model:FindFirstChildOfClass("Humanoid") and " (Player)" or " (NPC)") textLabel.TextColor3 = model:FindFirstChildOfClass("Humanoid") and CONFIG.ESP.PlayerColor or CONFIG.ESP.NPCColor textLabel.BackgroundTransparency = 1 textLabel.Font = Enum.Font.SourceSansBold textLabel.TextScaled = true textLabel.Parent = billboard -- Add to ESP Indicators table self.espIndicators[model] = billboard billboard.Parent = playerGui end function TARGET_MANAGER:removeESP(model) local billboard = self.espIndicators[model] if billboard and billboard.Parent then billboard:Destroy() self.espIndicators[model] = nil end end -- Rotation Management local ROTATION_MANAGER = {} ROTATION_MANAGER.__index = ROTATION_MANAGER function ROTATION_MANAGER.new(humanoidRootPart) local self = setmetatable({}, ROTATION_MANAGER) self.humanoidRootPart = humanoidRootPart self.rotationTween = nil return self end function ROTATION_MANAGER:rotateTo(targetPosition) local desiredCFrame = CFrame.lookAt(self.humanoidRootPart.Position, targetPosition) -- Define TweenInfo for almost instant rotation local tweenInfo = TweenInfo.new( CONFIG.ROTATION_DURATION, -- Very short duration CONFIG.ROTATION_EASING_STYLE, -- Linear for constant speed CONFIG.ROTATION_EASING_DIRECTION, -- Out direction 0, -- RepeatCount (0 = no repeat) false, -- Reverses 0 -- DelayTime ) -- Cancel any existing rotation tweens to prevent stacking if self.rotationTween and self.rotationTween.PlaybackState == Enum.PlaybackState.Playing then self.rotationTween:Cancel() end -- Create and play the tween self.rotationTween = TweenService:Create(self.humanoidRootPart, tweenInfo, {CFrame = desiredCFrame}) self.rotationTween:Play() end -- Initialization local targetManager = TARGET_MANAGER.new() local rotationManager = ROTATION_MANAGER.new(humanoidRootPart) -- Function to Handle Targeted Model Death (Already handled within TARGET_MANAGER) -- Function to Handle Mouse Clicks local function handleInputEnhanced(input, gameProcessed) if gameProcessed then return end if input.UserInputType == Enum.UserInputType.MouseButton1 then local mouse = player:GetMouse() local target = mouse.Target if target then -- Traverse up to find the model with Humanoid local model = target:FindFirstAncestorWhichIsA("Model") if model and model:FindFirstChildOfClass("Humanoid") then targetManager:trackModel(model) end end end end -- Function to Monitor New Models Added to Workspace local function onModelAdded(model) if model:IsA("Model") and model:FindFirstChildOfClass("Humanoid") then -- Optionally, auto-track certain models based on criteria -- Example: Auto-track all players (or NPCs) as they are part of the workspace -- For demonstration, we'll not auto-track and leave it to player clicks end end -- Function to Monitor Existing Models in Workspace local function monitorExistingModels() for _, model in ipairs(Workspace:GetChildren()) do if model:IsA("Model") and model:FindFirstChildOfClass("Humanoid") then -- Optionally, initialize something if needed end end end -- Connect to Workspace's ChildAdded event to handle models dynamically Workspace.ChildAdded:Connect(onModelAdded) -- Function to Handle ESP Toggle Keybind local function handleESPToggle(input, gameProcessed) if gameProcessed then return end if input.KeyCode == CONFIG.ESP.ToggleKey then toggleESPVisibility() elseif input.KeyCode == CONFIG.NOTIFICATIONS.ToggleKey then toggleNotifications() end end -- Function to Handle Connections for New Characters (Players) local function setupCharacter(character) if not character or not character:FindFirstChild("Humanoid") then return end local humanoid = character:FindFirstChildOfClass("Humanoid") -- Connect to Humanoid's Died event to untrack models humanoid.Died:Connect(function() local model = character:FindFirstAncestorWhichIsA("Model") if model then targetManager:untrackModel(model) end end) end -- Monitor existing players' characters for _, otherPlayer in ipairs(Players:GetPlayers()) do if otherPlayer ~= player and otherPlayer.Character then setupCharacter(otherPlayer.Character) end end -- Connect to PlayerAdded and CharacterAdded events Players.PlayerAdded:Connect(function(newPlayer) if newPlayer == player then return end newPlayer.CharacterAdded:Connect(setupCharacter) if newPlayer.Character then setupCharacter(newPlayer.Character) end end) -- Connect to PlayerRemoving to clean up ESP indicators Players.PlayerRemoving:Connect(function(removingPlayer) if removingPlayer.Character then targetManager:untrackModel(removingPlayer.Character) end end) -- Connect Input Listener for ESP Toggle UserInputService.InputBegan:Connect(handleESPToggle) -- Connect Enhanced Mouse Click Handler UserInputService.InputBegan:Connect(handleInputEnhanced) -- Function to Update Rotation in Heartbeat local function onHeartbeat(deltaTime) local trackedModels = targetManager:getTrackedModels() if #trackedModels == 0 then return -- No targets to rotate towards end -- Find the closest target local closestModel = nil local shortestDistance = math.huge local closestPosition = Vector3.new() for _, model in ipairs(trackedModels) do if model and model:FindFirstChild("HumanoidRootPart") then local distance = (model.HumanoidRootPart.Position - humanoidRootPart.Position).Magnitude if distance < shortestDistance then shortestDistance = distance closestModel = model closestPosition = Vector3.new( model.HumanoidRootPart.Position.X, humanoidRootPart.Position.Y, model.HumanoidRootPart.Position.Z ) end end end if closestModel then rotationManager:rotateTo(closestPosition) end end -- Connect Heartbeat for Rotation Updates RunService.Heartbeat:Connect(onHeartbeat) - Assistant