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

MouseEnter not working?

Asked by
Paldi 109
8 years ago

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)
0
What object is "script.Parent"? LateralLace 297 — 8y
0
TextButton gui Paldi 109 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago
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

0
You don't call the functions passed as the argument for the connect method. ScriptGuider 5640 — 8y
0
oh yeah i was just being dumb XD thanks! Paldi 109 — 8y
Ad
Log in to vote
5
Answered by 8 years ago

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.

0
+1 for just a little late User#5978 25 — 8y

Answer this question