Binding mousemovement to ContextActionService in one script overrides the mousemovement bind in another script. Any alternatives?

You can see above that the bind works as intended before equipping the gun.

I have 2 local scripts.
The first one rotates your waist motor6d locally and replicates it to the other clients using contextactionservice:bindaction on mousemovement and touch.

The other localscript is inside the gun which locks your camera to achieve an over the shoulder shooter camera and rotates the camera by also using the mousemovement bind.

The first will work up until you equip the gun.
It seems like the keybind inside the second localscript overrides the keybind inside the first localscript that lets the motor6d be replicated to the rest of the clients.

Right now I decided to put the function that replicates to the other clients inside the same .heartbeat that the local side of the first localscript uses.

The problem with this is that it will keep firing to the server even if the player is AFK, causing network lag.

I tried using inputbegan, but that’s only for when the player clicks the screen.

I found mouse.moved:connect() at the wiki site but apparently it’s deprecated.

Would this be useful?

or

Also look at the script example. You could poll the mouse location or delta value while the weapon is equipped and stop otherwise.

Mousedelta only works if your mouse is locked which would mean the replication wouldn’t work when the weapon is unequipped

Second one works though!
Will mark your answer as a solution if no one else has a more efficient one.

What I came up with using your second suggestion:

checkMouseMove function:

local lastMousePos = Vector2.new(0,0)
local function checkMouseMove()
	if UserInputService:GetMouseLocation() ~= lastMousePos then
		lastMousePos = UserInputService:GetMouseLocation()
		return true
	end
	return false
end

replicate function:

    local fireable = true
    local lastFire
	local function replicateMovement()
		if not fireable and tick()- lastFire > 1 then
			fireable = true
		end
		
		if fireable then
			ReplicatedStorage.mobileChange:FireServer(TorsoLookVector, HeadPosition, Point, Distance, Difference, WaistOriginC0)
			fireable = false
			lastFire = tick()
			print("fired")
		end
	end

heartbeat:

RunService.Heartbeat:Connect(function()
        if checkMouseMove() then
             replicateMovement()
       end
end)

Still also looking for something like heartbeat that runs every 0.05 seconds instead of every frame… Maybe a coroutine with a while wait(0.05)?

1 Like