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

How do I get MouseHoverLeave to work?

Asked by 8 years ago

I'm making a script that would make something appear on top of a brick when a mouse hovers over it, and disappear when the mouse stops.

However I am having problems with this

Here is my script:

script.Parent.Head.ClickDetector.MouseHoverLeave:connect(function(playerwhoclicked)
            if script.Parent:FindFirstChild(part.Object.Value) then
            wait(1)
            local ghostobjecty=script.Parent:FindFirstChild(part.Object.Value)
            ghostobjecty:Remove()
            end
        end)

This is what removes it However for some reason this script is triggered right after the MouseHoverEnter script, and I can't understand why it's not working. Please help.

1 answer

Log in to vote
1
Answered by 8 years ago

Your script will fire the moment a mouse has hovered a the Head and then leaves. You may want to use MouseHoverEnter and then MouseHoverLeave with eachother, as shown bellow. I changed playerwhoclicked because none of these events involve clicking.

local Head = script.Parent:WaitForChild("Head") -- Variable to shorten code

Head.ClickDetector.MouseHoverEnter:connect(function(PlrThatEntered) -- Not Clicking
    if script.Parent:FindFirstChild(part.Object.Value) then
            wait(1)
            local ghostobjecty = script.Parent:FindFirstChild(part.Object.Value)
    end
    Head.ClickDetector.MouseHoverLeave:connect(function(PlrThatLeft) 
                ghostobjecty:Remove()
    end)
end)

You really don't need the parameters because you don't seem to be using them.

If this helped, accept the answer, otherwise comment any questions or problems you may have!

0
The tabbing looks horrid, sorry'bout that alphawolvess 1784 — 8y
0
Im using the parameters for things outside of the script Volodymyr2004 293 — 8y
0
They wont work outside of the scope of the event. alphawolvess 1784 — 8y
Ad

Answer this question