Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to keep mouse stuck in a area?

Asked by 7 years ago

I have the basic understanding of mouse functions, here is my example of what I know:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

I know MouseTarget and such.

But is it possible to make a little box where the mouse clicker can go around but never go out of the box? I don't want the mouse to stay still however but I don't want it to go outside the box. I just don't know where to start with my semi-sophisticated scripting skill self.

0
I was told a fake mouse could be bound to a area stuck to a real mouse and that the real mouse player cannot do what I need. So I guess, could someone help me out with the fake mouse bounded to a box then? www3135 5 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

One method you could use, as you suggest in your comment, is a "fake mouse" system. That is:

  1. Hide the mouse cursor (see the Mouse Appearance tutorial)
  2. Have an ImageLabel that represents the user's mouse and move that around on screen to reflect their mouse position.
  3. Every time the user's mouse moves (you will need UserInputService to track this), update the ImageLabel's location on screen (keeping it within the desired bounds).
  4. Every time the user clicks their mouse, all your gui code will need to use your custom mouse's coordinates (based on the ImageLabel's position, for instance) rather than the ones given by the event.

This is a lot of work, but it gives you the most control.

You might also consider using UserInputService.MouseBehavior, which allows you to lock the mouse using one of these values. If you can change your control system to work with a locked mouse position, it'll be a lot easier to code.

Ad
Log in to vote
0
Answered by 7 years ago

Make a fake mouse with the real mouse giving input to move it, but program it so it doesn't go outside.

Answer this question