Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a local mouse hover filter?

Asked by 6 years ago

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

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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.

0
I can re-edit this. Thanks! magicguy78942 238 — 6y
Ad

Answer this question