0% found this document useful (0 votes)
36 views2 pages

Grah

The document contains a script for targeting players in a game using Roblox Lua. It defines various parameters for prediction, offset, and smoothness, and includes functions to identify and track a target based on mouse position and player health. The script also handles user input to toggle targeting and updates the camera position based on the target's movement.

Uploaded by

omarlook1020
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)
36 views2 pages

Grah

The document contains a script for targeting players in a game using Roblox Lua. It defines various parameters for prediction, offset, and smoothness, and includes functions to identify and track a target based on mouse position and player health. The script also handles user input to toggle targeting and updates the camera position based on the target's movement.

Uploaded by

omarlook1020
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/ 2

getgenv().prediction = 0.

102
getgenv().offset = 0.6
getgenv().resolver = false
getgenv().smoothness = 1

local players = game:GetService("Players")


local localplayer = players.LocalPlayer
local mouse = localplayer:GetMouse()
local userinputservice = game:GetService("UserInputService")
local runservice = game:GetService("RunService")
local currentCamera = workspace.CurrentCamera

local victim = nil


local targeting = false

local function target()


local target = nil
local shortdistance = math.huge

for _, v in next, workspace:GetDescendants() do


if v.Parent and v:IsA("Model") and v ~= localplayer.Character then
if v:FindFirstChildOfClass("Humanoid") then
if v:FindFirstChildOfClass("Humanoid").Health > 0 then

pcall(function()
local worldtoviewportpoint, onscreen =
currentCamera:WorldToViewportPoint(v:FindFirstChildOfClass("Humanoid").RootPart.Pos
ition or v.PrimaryPart.Position)
local distance = (Vector2.new(mouse.X, mouse.Y) -
Vector2.new(worldtoviewportpoint.X, worldtoviewportpoint.Y)).Magnitude

if math.huge > distance and distance < shortdistance and onscreen then
target = v
shortdistance = distance
end
end)
end
end
end
end
return target and (target.PrimaryPart or
target:FindFirstChildOfClass("Humanoid").RootPart)
end

userinputservice.InputBegan:Connect(function(input, processed)
if processed then
return
end

if input.KeyCode == Enum.KeyCode.Q then


targeting = not targeting

if targeting then
victim = target()
else
if victim ~= nil then
victim = nil
end
end
end
end)

local velocity = Vector3.new(0,0,0)


local oldpos = Vector3.new(0,0,0)

runservice.Heartbeat:Connect(function(deltaTime)
if victim and victim.Parent then
local currentpos = victim.Position
local displacement = currentpos - oldpos

local vector = displacement / deltaTime

velocity = velocity:Lerp(Vector3.new(
vector.X,
vector.Y*0.94*getgenv().offset,
vector.Z
), 0.4)

oldpos = currentpos
end
end)

runservice.RenderStepped:Connect(function()
local pos

if targeting and victim and victim.Parent then


if victim.Parent:FindFirstChildOfClass("Humanoid") then
if victim.Parent:FindFirstChildOfClass("Humanoid").Health > 0 then

if getgenv().usePrediction then
if getgenv().resolver then
pos = Vector3.new(
victim.Position.X,
victim.Position.Y,
victim.Position.Z) + (velocity * getgenv().prediction)
else
pos = Vector3.new(
victim.Position.X,
victim.Position.Y,
victim.Position.Z) + (victim.velocity * getgenv().prediction)
end
else
pos = Vector3.new(victim.Position.X,
victim.Position.Y,
victim.Position.Z)
end

currentCamera.CFrame =
currentCamera.CFrame:Lerp(CFrame.new(currentCamera.CFrame.Position, pos),
getgenv().smoothness)
end
end
end
end)

You might also like