#Lock system stays on old target

4 messages · Page 1 of 1 (latest)

fringe fulcrum
#

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```
sly osprey
#

and also, your should lock on the player instead so you can get the player.Character

#
local function lockOn(entity)
  local oldChar = entity.Character
  [RenderStepEvent]()
    if entity.Character ~= oldChar then return end -- The character changed
    ...
  end
end

or something like that, but i dont really fully understood what youre doing, and what youre trying to achieve