When I unlock and lock onto a new character it locks onto the old one, but the icon i have is above the new one, so its choosing the right one. im guessing its got to be the way I manipulate camera, but im not sure:
local camera = game.Workspace.CurrentCamera
local rs = game:GetService("RunService")
local canlock = true
local function lockon(entity)
canlock = true
local Target = entity.Parent.HumanoidRootPart
rs.RenderStepped:Connect(function()
if Target and canlock then
local hrp = player.Character.HumanoidRootPart
local Mag = (hrp.Position - Target.Position).Magnitude
if Mag < 545 then
camera.CFrame = CFrame.lookAt(camera.CFrame.Position, Target.Position) * CFrame.new(2, 1, 0)
local direction = (hrp.Position - Target.Position).Unit * Vector3.new(-1, -.15, -1)
hrp.CFrame = CFrame.lookAt(hrp.Position, hrp.Position + direction)
else
player.Character.Humanoid.AutoRotate = true
coroutine.close()
end
end
end)
end
local locked = false
local function unlock(targeticon, entity)
targeticon:Destroy()
canlock = false
locked = false
end```