0% found this document useful (0 votes)
166 views4 pages

Message

This script implements an aim assist feature for a game, allowing players to toggle it on and off and lock onto targets with sticky aim. It includes settings for aim smoothness, prediction for airborne and grounded targets, and different aiming methods. The aim assist runs continuously or at set intervals based on user preferences and responds to specific key inputs for toggling and locking targets.

Uploaded by

meqisbackmeq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views4 pages

Message

This script implements an aim assist feature for a game, allowing players to toggle it on and off and lock onto targets with sticky aim. It includes settings for aim smoothness, prediction for airborne and grounded targets, and different aiming methods. The aim assist runs continuously or at set intervals based on user preferences and responds to specific key inputs for toggling and locking targets.

Uploaded by

meqisbackmeq
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

local Players = game:GetService("Players")

local UserInputService = game:GetService("UserInputService")


local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local LocalPlayer = Players.LocalPlayer


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

-- Aim Assist Settings


local Aim = {
Enabled = true, -- Toggle Aim Assist (Press "E" to toggle)
NoSleep = true, -- If true, aim assist runs every frame (NoSleep
Mode)
Smoothness = 0.15, -- Aim Smoothness (Lower = Faster Aim)
AimType = "Camera", -- Options: "Camera", "MouseMove", "MousePosition"
Range = 1000, -- Max Aim Distance
ToggleKey = Enum.KeyCode.Q, -- Key to toggle Aim Assist
Easing = Enum.EasingStyle.Sine, -- Smooth movement style
Direction = Enum.EasingDirection.Out,

-- Normal Target Prediction (Ground)


Prediction = {
Value = 0.5, -- Prediction value for target movement on the
ground (0.0 to 1.0)
Target = {"Head", "Torso"} -- Target parts on ground
},

-- Air Prediction (Only works if enabled)


Air = {
Enabled = true, -- Set false to disable air prediction
Value = 0.75, -- More prediction for air targets (0.0 to
1.0)
Target = {"Head"} -- Prioritize headshots in air
}
}

-- Sticky Aim Variables


local stickyTarget = nil -- The player we're currently locked onto
local stickyTargetPart = nil -- The part we're aiming at on that player

-- Check if Target is Airborne


local function IsAirborne(character)
local humanoid = character:FindFirstChildOfClass("Humanoid")
return humanoid and humanoid:GetState() == Enum.HumanoidStateType.Freefall
end

-- Find Closest Target


local function GetTarget()
local closest = nil
local distance = Aim.Range
local isAir = false

-- If sticky aim is enabled and we have a locked target, return that target
if stickyTarget then
-- Sticky aim: Only track the locked target
return stickyTargetPart, IsAirborne(stickyTarget.Character)
end
-- Otherwise, find the closest target
for _, player in ipairs(Players:GetPlayers()) do
if player ~= LocalPlayer and player.Character then
local inAir = IsAirborne(player.Character)
local config = Aim.Prediction

-- Use air settings if enabled


if inAir and Aim.Air.Enabled then
config = Aim.Air
end

for _, bodyPart in ipairs(config.Target) do


local part = player.Character:FindFirstChild(bodyPart)
if part then
local screenPos, onScreen =
Camera:WorldToViewportPoint(part.Position)

if onScreen then
local mousePos = Vector2.new(Mouse.X, Mouse.Y)
local targetPos = Vector2.new(screenPos.X, screenPos.Y)
local dist = (mousePos - targetPos).Magnitude

if dist < distance then


closest = part
distance = dist
isAir = inAir
end
end
end
end
end
end

return closest, isAir


end

-- Aim at Target Smoothly


local function AimAt(target, inAir)
if not target then return end

-- Choose prediction settings based on air or ground


local config = Aim.Prediction
if inAir and Aim.Air.Enabled then
config = Aim.Air
end

-- Prediction based on value (0.0 to 1.0)


local predictionAmount = config.Value -- This will be from 0.0 to 1.0
local predictedPos = target.Position + (target.Velocity * predictionAmount)
local screenPos = Camera:WorldToViewportPoint(predictedPos)

-- Calculate the required offset to the target


local offsetX = (screenPos.X - Mouse.X) * Aim.Smoothness
local offsetY = (screenPos.Y - Mouse.Y) * Aim.Smoothness

-- Fixing camera offset issue: We use the mouse position to adjust the camera
smoothly without causing vertical displacement issues.
if Aim.AimType == "Camera" then
-- Smooth camera movement
local targetCFrame = Camera.CFrame:PointToWorldSpace(Vector3.new(offsetX,
offsetY, 0)) -- Adjust the CFrame based on the offset.
local tweenInfo = TweenInfo.new(Aim.Smoothness, Aim.Easing, Aim.Direction)
local tween = TweenService:Create(Camera, tweenInfo, {CFrame =
targetCFrame})
tween:Play()
elseif Aim.AimType == "MouseMove" then
-- Smooth mouse movement
local moveX = offsetX
local moveY = offsetY
mousemoverel(moveX, moveY)
elseif Aim.AimType == "MousePosition" then
-- Instant mouse snap
mousemoverel(screenPos.X - Mouse.X, screenPos.Y - Mouse.Y)
end
end

-- Aim Assist Logic (NoSleep Mode)


local function RunAimAssist()
if Aim.Enabled then
local target, inAir = GetTarget()
if target then
AimAt(target, inAir)
end
end
end

-- Handle NoSleep Mode


if Aim.NoSleep then
RunService.RenderStepped:Connect(RunAimAssist)
else
RunService.Heartbeat:Connect(function()
if Aim.Enabled then
RunAimAssist()
end
end)
end

-- Toggle Aim Assist and Lock Sticky Aim


UserInputService.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == Aim.ToggleKey then
Aim.Enabled = not Aim.Enabled
end

-- Lock the aim on the target (Sticky Aim)


if input.KeyCode == Enum.KeyCode.F then -- You can change this to any key you
prefer
-- Only lock to the target if no target is already locked
if not stickyTarget then
local target, inAir = GetTarget()
if target then
stickyTarget = target.Parent -- Lock the entire player, not just
the part
stickyTargetPart = target -- Lock the part being aimed at
end
end
end
-- Unlock Sticky Aim
if input.KeyCode == Enum.KeyCode.G then -- Change this to any key for
unlocking
stickyTarget = nil
stickyTargetPart = nil
end
end)

You might also like