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

Adding a loop for MouseHoverEnter?

Asked by 7 years ago
Edited 7 years ago

Well, I'm just messing around on studio and I'm trying to have a brick change color randomly while a mouse is on it, and stay red while the mouse is not on it. I can easily have it change color, however, I able to loop the brick changing color while the mouse is on it, but not change back to red. Any thoughts, feedback, etc, would be helpful. Thanks. Edit: I realize now that the mousehover enter is an event and not a function and it only triggers a function. Anything I can use to make a while or if statement?

1 answer

Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
7 years ago
Edited 7 years ago

You would use the other ClickDetector event called MouseHoverLeave

I'm not so sure about whet you mean when you say that you are looping it. However, you would probably use this:

script.Parent.ClickDetector.MouseHoverEnter:Connect(function(player)
    script.Parent.BrickColor = BrickColor.new("Bright green")
    script.Parent.ClickDetector.MouseHoverLeave:Wait()
    script.Parent.BrickColor = BrickColor.new("Bright red")
end)

Edit:

If you want to make it so that it constantly changes color while your mouse is over it, then be red when the mouse leaves, here is what you do:

script.Parent.ClickDetector.MouseHoverEnter:Connect(function(player)
    local hover = true
    local connection = script.Parent.ClickDetector.MouseHoverLeave:Connect(function(player)
        hover = false
    end)
    while hover do
        wait(0.1)
        script.Parent.BrickColor = BrickColor.Random()
    end
    script.Parent.BrickColor = BrickColor.new("Bright red")
end)
0
Yes, I realize that, I meant I wanted the Brick to constantly, lets say every (.1) seconds, change color while the mouse is on it, and when the mouse leaves I want it to return to red. TiredMelon 405 — 7y
0
Awesome thanks! TiredMelon 405 — 7y
Ad

Answer this question