Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Do I Make A GUI Visible Only If Mouse Is Hovering Over An Object?

I made a door model with a clickdetector. I Gui I made Gui labels and then put in this localscript

local player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui")
local screenGui = gui:WaitForChild("KeyE")
local imageLabel = screenGui:WaitForChild("EButton")

local clickdetector = game.workspace.Door:WaitForChild("ClickDetector")

screenGui.Enabled = false

clickdetector.MouseHoverEnter:connect(function()
	screenGui.Enabled = true
end)


When I hover over the the model, it makes the gui visible.. when it is not hovering, it does not go away... how do I do this thank you.

--I wish to make the gui pop up when my mouse is hovering over the model and disappear when it is not. Thank you

1 answer

✓ Accepted answer

You’ll have to use an event called “MouseHoverLeave” if you want the GUI to be disabled when the player hovers away.

Here’s your fixed script. I added the function in so it should work :

local player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui")
local screenGui = gui:WaitForChild("KeyE")
local imageLabel = screenGui:WaitForChild("EButton")

local clickdetector = game.Workspace.Door:WaitForChild("ClickDetector")

screenGui.Enabled = false

clickdetector.MouseHoverEnter:Connect(function()
    screenGui.Enabled = true
end)

clickdetector.MouseHoverLeave:Connect(function()
    screenGui.Enabled = false
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.