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

How do you make a local mouse hover filter?

Example:

There are 100 parts named "SelectionBox" in the workspace. There's a LocalScript inside the player when ever the player's mouse hovers on the part named "SelectionBox" it will destroy it!

|FAILED STRATEGY 1|

How:

  • Create a ClickDetector inside each Box
  • Connect into single one of it (1. Waste of time)
  • Add this script:
script.Parent.ClickDetector.MouseHoverEnter:connect(function()
	script.Parent:Destroy()
end)

(2. Creates a lag a.k.a low response to the whole server)

|FAILED STRATEGY 2| <- Changing the box properties instead of destroying it

How:

  • Add this in the LocalScript:
--Get Mouse
mouse.Moved:connect(function()
	if mouse.Target ~= nil then
		if mouse.Target.Name == "SelectionBox" then
			box = mouse.Target --Save the box in-case the mouse unhovers it
			box.Transparency = 0.5
	        else
			box.Transparency = 0
		end
	end
end)

(But what if you hover on another part instead of the SelectionBox? Well the script will also cause an error.) (But what if the SelectionBox you just hover get destroyed? Well the script will also cause an error.)

1 answer

✓ Accepted answer

If you wanted to make the boxes half transparent while you are hovering over them you can do this:

local mouse = game.Players.LocalPlayer:GetMouse()
local box
mouse.Move:Connect(function()
	local targ = mouse.Target
	if targ and targ.Name == "SelectionBox" and targ:IsA("BasePart") then
		if box and targ ~= box then
			box.Transparency = 0
		end
		targ.Transparency = 0.5
		box = targ
	end
end)

Keep in mind if you are using FilteringEnabled and you want all players to see the boxes go transparent, you need to use Remote Events.

1 comment

0

I can re-edit this. Thanks!

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