Pretty bad code, ill fix it later, but why does the player go out of view instead of the camera following the player fully from behind, all i want the :Lerp() for is to get the midpoint and look at the midpoint
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:FindFirstChildOfClass("Humanoid")
local humRP = hum.RootPart
--local otherHP = plr.PlayerGui.OtherHPBarGui
--otherHPFrame = otherHP.HealthbarFrame.HealthBar
local uis = game:GetService("UserInputService")
hum:SetAttribute("Locked", true)
local function getTarget(input: InputObject, gameProcessedEvent: boolean)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton3 then
local camera = workspace.CurrentCamera
local cameraCF = camera.CFrame
local camDefPos = cameraCF
local length = 66.6667
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {char}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local cameraCF = camera.CFrame
local raycastResult = workspace:Raycast(cameraCF.Position, cameraCF.LookVector * length, raycastParams)
if raycastResult.Instance.Parent:IsA("Model") then
if raycastResult.Instance.Parent:FindFirstChildOfClass("Humanoid") then
local Target = {
["Head"] = raycastResult.Instance.Parent.Head,
["Model"] = raycastResult.Instance.Parent,
["Hum"] = raycastResult.Instance.Parent:FindFirstChildOfClass("Humanoid"),
["RootPart"] = raycastResult.Instance.Parent:FindFirstChildOfClass("Humanoid").RootPart,
}
if hum:GetAttribute("Locked", true) then
local mouse = game:GetService("Players").LocalPlayer:GetMouse()
--otherHP.Enabled = true
local function LockOn()
humRP.CFrame = CFrame.new(humRP.Position,Vector3.new(Target.Model.Position.X, humRP.Position.Y, Target.Model.Position.Z))
camera.CFrame = CFrame.new((humRP.Position + Vector3.new(0, 3, 10)),humRP.Position:Lerp(Target.Head.Position, 0.5))
local health = Target.Hum.Health
local f = health/100
--otherHP.Adornee = Target
--otherHPFrame:TweenSize(UDim2.new(f,0,1,0),"Out","Quad",0.25)
end
game:GetService("RunService"):BindToRenderStep("LockOn", Enum.RenderPriority.Camera.Value + 1, LockOn)
repeat
task.wait()
camera.CameraType = Enum.CameraType.Scriptable
until
camera.CameraType == Enum.CameraType.Scriptable
hum:SetAttribute("Locked", false)
print("alpha")
elseif hum:GetAttribute("Locked") == false or hum.Died or Target.Hum.Died then
--ill do this later
hum:SetAttribute("Locked", true)
end
else
print("nah")
end
end
end
end
uis.InputEnded:Connect(function(input: InputObject, gameProcessedEvent: boolean)
getTarget(input, gameProcessedEvent)
end)