Binding mouse movement to function not working

--// Have Hover follow the mouse
local function FollowMouse()
	print("Follow")
end

print("ACTIVE")
ContextActionService:BindAction(
	"FollowMouse",
	FollowMouse,
	false,
	Enum.UserInputType.MouseMovement
)

I’m getting active to print, but not follow. Unsure what I am doing wrong here?

As far as I know, context actions only fire when the input state changes. Mouse movement’s user input state is always set to Change.

Your script is fine that should be printing ‘Follow’.
Is your code in a LocalScript and in a place where they can run(Workspace, StarterGui, StarterPack or StarterPlayerScripts)?

Yes, and it doesn’t work. LocalScript inside a ScreenGui

Thats odd.
Have you tried printing something after binding the action?
I tested the script myself with a LocalScript inside a ScreenGui and it worked for me.

I assume you want it so that whenever the mouse moves, it prints that statement inside the function?

Here’s the full functions. Prints inside the Toggle are all accurate. Still no follow print

--// Have Hover follow the mouse
local function FollowMouse()
	print("FOLLOW")
end

--// Toggle the Hover
local function Toggle(active, text)
	if active then
		Hover.Label.Text = text
		print("ACTIVE")
		ContextActionService:BindAction(
			"FollowMouse",
			FollowMouse,
			false,
			Enum.UserInputType.MouseMovement
		)
		print("CLEAR")
		HUD.Enabled = true
	else
		print("UNBIND")
		ContextActionService:UnbindAction("FollowMouse")
		
		HUD.Enabled = false
	end
end

HoverController.Event:Connect(Toggle)

Shudnt u add the bindaction params to the function?

local function FollowMouse(actionName, InputState, inputObject)
1 Like

Not necessary. Should not affect my script. The function itself is not firing

1 Like

If it’s working in an empty environment and not your own environment then you likely have some script/plugin which is causing a conflict somehow, perhaps something else is manipulating the mouse.

Even with a completely gibberish name, it still don’t work

ContextActionService:BindAction(
			"fsfwe jefjwe 0ufhweoifweoch wqe98ur23ur",
			FollowMouse,
			false,
			Enum.UserInputType.MouseMovement
		)

Try adding my params and check the result.

Still doesn’t work with the params

Are u testing in Studio,? If so, then try publishing the game and testing it.

If it don’t work in studio, it’s not gonna work in game

Maybe not, but trying doesnt hurt.

I doubt this is the cause but I’m gonna rule it out in case.
Is there anything else that is binding Enum.UserInputType.MouseMovement?

If there isn’t then I’ve got nothing.

Not in my script, I don’t know if plugins would affect this though

Plugins do affect ContextActionService and after doing a quick test looks like they will always bind after the scripts load when playtesting.

You could try @Mystxry12’s solution and if it works outside of studio you should be fine.
Just remember to mark them as the solution if it does

Just published, still don’t work anyway