Overlap shiftlocks priority

I have a lock on to character script and it works fine, however when I enable shiftlock its priority is way higher than the lock on and I don’t know how to prevent that without removing shiftlock which I dont want to do.

How would I go about fixing that? I already used CFrame.lookAt and it didn’t work.

The lock on script (local):

local cas = game:GetService("ContextActionService")
local TweenService = game:GetService("TweenService")

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local mouse = plr:GetMouse()

local lockedOn = false

local function getMouseOverChar()
	local hit = mouse.Target
	local p = Instance.new("Part")
	local eChar = hit:FindFirstAncestorWhichIsA("Model")
	if eChar then
		local hum = eChar:FindFirstChildOfClass("Humanoid")
		if hum then
			return eChar
		end
	end
end

local function lockOn(actionName, inputState, inputObject)
	if actionName == "lockOn" and inputState == Enum.UserInputState.Begin then
		if lockedOn == false then
			local eChar = getMouseOverChar()
			print(eChar)
			if eChar then
				local ehrp = eChar:WaitForChild("HumanoidRootPart")
				--begin lock on
				print("BEGIN")
				lockedOn = true
				while lockedOn == true do task.wait()
					TweenService:Create(hrp, TweenInfo.new(0), {
						CFrame = CFrame.lookAt(hrp.Position, Vector3.new(
							ehrp.Position.X,
							hrp.Position.Y,
							ehrp.Position.Z
							))
					}):Play()
				end
			end
		else
			lockedOn = false
		end
		
	end
end

cas:BindAction("lockOn", lockOn, true, Enum.KeyCode.L)

I know you said you don’t want to remove shiftlock, but would it be okay for you to disable it when you’re locked on and then enable it when you’re done?

I could work with that as well

You could fork the default player scripts or you can use a RenderStepped event instead of a while true (which doesn’t sound very convenient in this case).

local connection = nil;
-- other stuff
if eChar then
	local ehrp = eChar:WaitForChild("HumanoidRootPart")
	--begin lock on
	print("BEGIN")
	lockedOn = true
    if connection ~= nil then 
       connection:Disconnect(); 
       connection = nil; 
    end
    connection = game:GetService("RunService").RenderStepped:Connect(function()
        if lockedOn == false then
            connection:Disconnect();
            connection = nil;
        else
            TweenService:Create(hrp, TweenInfo.new(0), {
			CFrame = CFrame.lookAt(hrp.Position, Vector3.new(
			      ehrp.Position.X,
			      hrp.Position.Y,
			      ehrp.Position.Z
			 ))}):Play()
        end;
    end);
1 Like