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

How do I check if the mouse is in within a textbutton without the mouseenter function?

Asked by 5 years ago
function aa()

while wait() do

if script.Parent.TextButton.MouseEnter then

print("A")

end

end

end



aa()

I know theres a function called MouseEnter, but I need an if statement and not a function. How would I make it work?

0
I have edited my answer! I hope it solves your problem. User#24403 69 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

GuiObject.MouseEnter is not a property or a function.

It's an event.

You can listen for this event.

lua textButton.MouseEnter:Connect(function(x, y) print(string.format("Player clicked at coordinates: (%d, %d)", x, y)); end);

The x and y parameters are the 2D X-Y coordinates of the mouse when hovered over the button


Edit

I misunderstood your question the first time.

What you can do is have a variable, it will start off as false, set it to true when they are hovering over the button, false when they stop.


```lua local isHovering = false;

textButton.MouseEnter:Connect(function(x, y) isHovering = true; end);

textButton.MouseLeave:Connect(function(x, y) isHovering = false; end); ```

If you need to check that they are hovering...

lua if (isHovering) then --// do something... end


Side note

Do not use while wait() do. It only works because of a hack; a trick. Use

lua while true do ... end

It's clearer.

0
Yes, I know. I stated that in the question. I'm looking for something that works like an if statement. Thesquid13 301 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Hello, when I script UI's I like to be precise like you. Therefore you may use the following script to achieve the result:

pointer = game:GetService("UserInputService")
-- now we do the script, very easy
function response(theTextBox)
-- your code
end

if pointer.TextBoxFocused:Wait() then
-- I'm not sure if wait is a one-off thing...
pointer.TextBoxFocused:Connect(response)
end

-- the TextBoxFocusReleased is the reverse

Answer this question