How do I disable mouse input from a player?

Hey recently I was making an npc, where player 1 controls and moves it and player 2 uses a sword and attacks. Recently I noticed that even though player 1 had its backpack disabled when player 2 equipped the sword player 1 could click and use the sword. Is there anyway I can disable mouse input for a player?

If you want to know, I set Player1’s character as the NPC to allow smooth movement and so I dont have to make my own movement script. and Player 2 simply gets anchored, becomes invisible and gets their current camera set to the npc’s humanoid

1 Like

Hello!
I think I get your question, but could you perhaps provide with your script (or part of it) so I can get an overview over your problem?

Also tried using if statements to check whether the tool is equipped or not?

You cannot disable input, just whether or not you are listening to the input.

Try making a check within your tool’s swing function to see if a player should be able to swing in the first place, and then proceed with the function or return it early if they are not allowed to swing.

2 Likes

Assuming you’re (hopefully) relaying that information through some sort of remote event/function to the server, you can have the server check who is controlling the NPC at the time and have it so the server only accepts the coordinates of the current controller. There’s no actual way to disable mouse inputs (from my knowledge), but you can disable whether they’re accepted.

Nevermind, I managed to achieve this by putting an invisible TextButton in the players view so even if they click, they cannot use the sword. This wont be a problem for movement either as the players are locked first person anyway.

Exploiters can work around that tho