Make eye follow cursor

Hey Robloxians!

I was wondering how to make an eye move just like in the video below:

I would like the eye to follow the mouse cursor which requires a way to get the direction of the cursor and a way to set a fixed distance to the end of the eye shape. How would I do this? Is there any method for this? I would appreciate any help.

Have a great day, iamajust

1 Like

On a local script try something like this:

local mouse = game.Players.LocalPlayer:GetMouse()
local X, Y = mouse.X, mouse.Y

Probably you want to check the mouse position on a RunService, like RenderStep or choose the best for you.
I supose the eye is a GUI element, an ImageLabel maybe, so, you just change the position of the GUI element based on the client mouse position connected to the RunService

mouse = game.Players.LocalPlayer:GetMouse()
X, Y = mouse.X, mouse.Y
Eye = script.Parent
while task.wait()  do
Eye.Position =,Y)
1 Like

Thanks for trying to help me, but that isn’t what I need help with. I know how to get the position of the mouse, but how would I get the direction? If the cursor is out of the eye shape, I don’t want the eye to go out of the eye shape. I want the eye to ‘look at the cursor’.

I would try to use an if statement, checking if the mouse coordinates are inside the background image (eyeball) if the coordinates are inside the eyeball do the position update, if not do nothing. This is not the best example, but something like this:

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

local BKG_Eyeball = script.Parent.EyeBall_Image

	local LeftLimit = BKG_Eyeball.Position.X.Offset + BKG_Eyeball.Size.X.Offset/2
	if mouse.X > LeftLimit then
		script.Parent.Iris_Image.Position =, mouse.X, 0, mouse.Y)

Should be done for both sides left and right on X, and up and down for Y.
Its a very basic example, the idea is you state a boundary box where the if statement will filter if the movement should happen or not

1 Like

I know this is hard and I really wanna thank you for trying. You don’t have to keep spending effort on me, but just so everyone can read: This isn’t a solution to my problem. I want the eye to look at the cursor, not be at the position of the cursor. This script wouldn’t work for that because the cursor can still change direction outside of the eye shape and the boundaries also aren’t square.

1 Like