We use cookies on this site to enhance your user experience
Collapse Sidebar


The MouseHoverLeave event fires when a player’s Mouse|mouse moves off of the ClickDetector's parent. This event fires when using either a Script or LocalScript.

Due to the nature of user input, you ought not depend on all ClickDetector/MouseHoverEnter|MouseHoverEnter events to fire a matching MouseHoverLeave event.

The player does not have to click the ClickDetector for this event to fire. If you want an function to run when the player clicks, you can use ClickDetector/MouseClick and ClickDetector/RightMouseClick events.


Name Type Default Description

The Player whose mouse stopped hovering on the ClickDetector

Code Samples

Mouse Hovering On and Off of a ClickDetector

The below code will print “Oh my… PlayerName left the confines of my parent” when a player’s mouse is moved off of the ClickDetector|ClickDetector's parent, replacing “PlayerName” with the player’s name.

It will also print “Oh my… PlayerName hovered over my parent” when a player’s mouse hovers over the ClickDetector’s parent, replacing “PlayerName” with the player’s name.

In order for this example to work as expected, it must be placed in a Script or LocalScript whose parent is the ClickDetector.

   print("Oh my... " .. Player.Name .. " left the confines of my parent")

   print("Oh my... " .. Player.Name .. " hovered over my parent")

Creating a ClickDetector Door

The code sample below demonstrates the functionality of a ClickDetector and its properties and events.

First the code creates a ClickDetector and set’s its Instance/Parent|parent to the door. It also sets the ClickDetector/MaxActivationDistance|maximum distance players can interact with the ClickDetector to 10 studs and set’s the ClickDetector’s ClickDetector/CursorImage|CursorImage to:

Custom cursor image

Then, the code connects the ClickDetector to several events, including changing the door’s BasePart/Transparency when the player’s mouse hovers ClickDetector/MouseHoverEnter|on and ClickDetector/MouseHoverLeave|off off the door. The player opens the door by ClickDetector/MouseClick|left clicking their mouse while over the ClickDetector and closes the door by ClickDetector/RightMouseClick|right clicking their mouse while over the ClickDetector.

This code works in a Script and a LocalScript as long as the script’s parent is the door BasePart|Part.

-- The door 'BasePart'
local door = script.Parent

-- Asset ID of the image you want the to set the cursor to
local CursorId = "2287179355"

-- Create a ClickDetector
local ClickDetector = Instance.new("ClickDetector")
ClickDetector.Parent = door
ClickDetector.MaxActivationDistance = 10
ClickDetector.CursorIcon = "rbxassetid://"..CursorId

-- Make door slightly transparent when mouse hovers over it
	door.Transparency = 0.1

-- Door is not transparent when mouse is not hovering over it
	door.Transparency = 0

-- Open door on left mouse click
	door.Transparency = 0.8
	door.CanCollide = false

-- Close door on right mouse click
	door.Transparency = 0.1
	door.CanCollide = true