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

Hover Over A Part Script NOT Working? Please Help!

Hello. I'm Trying To Make A Script That When Your Mouse Hovers Over A Brick, A GUI Shows; However, It Doesn't Show The GUI. Any Help?

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local gooi = game.Workspace.DoorInHouse
 
Mouse.Move:connect(function()
    if Mouse.Target and Mouse.Target == gooi then
        Player.PlayerGui.A.DoorStart.Visible = true
    elseif Mouse.Target and Mouse.Target ~= gooi then
        Player.PlayerGui.A.DoorStart.Visible = false
    end
end)

It's In A Local GUI And FilteringEnabled Is Active.

1 comment

0

@NeonHaxOfficial Does it work in studio?

1 answer

Your code looks okay; it's probably a problem with god forsaken capitalization (and therefore paths to objects in the game hierarchy).

Working in a FilteringEnabled, non-experimental game:

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

mouse.Move:connect(function()
	if(mouse.Target ~= nil)then
		if(mouse.Target == game.Workspace.Baseplate)then
			player.PlayerGui.ScreenGui.Frame.Visible = true;
		else
			if(player.PlayerGui.ScreenGui.Frame.Visible == true)then
			player.PlayerGui.ScreenGui.Frame.Visible = false;
end
		end
	end
end)

I would recommend looking into UserInputService as well, which features (for example) checks on whether an event was processed by the Roblox client.

http://wiki.roblox.com/index.php?title=API:Class/UserInputService

Arguably better code:

local player = game.Players.LocalPlayer;
local mouse = player:GetMouse();
local inputservice = game:GetService("UserInputService");

inputservice.InputChanged:connect(function(input, handled)
	if((input.UserInputType == Enum.UserInputType.MouseMovement) and not handled)then
		if(mouse.Target ~= nil)then
			if(mouse.Target == game.Workspace.Baseplate)then
				player.PlayerGui.ScreenGui.Frame.Visible = true;
			else
				if(player.PlayerGui.ScreenGui.Frame.Visible == true)then
					player.PlayerGui.ScreenGui.Frame.Visible = false;
				end
			end
		end
	end
end)

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