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

MouseEnter not working?

How do i make this work? Yet it does nothing and i get this error in the output :11: attempt to call field 'MouseEnter' (a userdata value)

text = script.Parent.Parent.TextLabel

function OnOver()
	text.Text = "random text"
end

function OffOver()
	text.Text = "random text2"
end

script.Parent.MouseEnter(OnOver)
script.Parent.MouseLeave(OffOver)

2 comments

0

What object is "script.Parent"?

0

TextButton gui

2 answers

✓ Accepted answer
text = script.Parent.Parent.TextLabel

function OnOver()
    text.Text = "random text"
end

function OffOver()
    text.Text = "random text2"
end

script.Parent.MouseEnter:connect(OnOver())
script.Parent.MouseLeave:connect(OffOver())

you forgot to connect the events to the functions

2 comments

0

You don't call the functions passed as the argument for the connect method.

0

oh yeah i was just being dumb XD thanks!

Problem:

Simple mistake; you're simply forgetting the connect method that's required to bind functions with events. This method is called from the event of the object, and the argument passed through the method is the function that will execute whenever the event is triggered.

Fix:

local text = script.Parent.Parent.TextLabel

local function OnOver()
    text.Text = "random text"
end

local function OffOver()
    text.Text = "random text2"
end

-- Calling the "connect" method on the events, and passing the function as the argument.
script.Parent.MouseEnter:connect(OnOver)
script.Parent.MouseLeave:connect(OffOver)

Hope this helped.

1 comment

0

+1 for just a little late

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