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

How do I fix the mouse hover script?

Asked by
Kitorari 266 Moderation Voter
8 years ago
Edited 8 years ago
01function MouseEntered()
02 
03    local T = game.Players:GetPlayerFromCharacter(MouseEntered.Parent).PlayerGui.ScreenGui.Cursor.Text
04    T.Text = T.text.new("a")
05    T.Visible = true
06end
07 
08 
09function MouseLeft()
10        local T = game.Players:GetPlayerFromCharacter(MouseLeft.Parent).PlayerGui.ScreenGui.Cursor.Text
11    T.Text = T.text.new("Lable")
12    T.Visible = false
13end
14 
15script.Parent.ClickDetector.MouseHoverEnter:connect(MouseEntered)
16 
17script.Parent.ClickDetector.MouseHoverLeave:connect(MouseLeft)

It says

20:41:25.192 - Workspace.object.food.Script:24: attempt to index global 'MouseLeft' (a function value)

20:41:25.192 - Workspace.object.food.Script:24: attempt to index global 'MouseEntered' (a function value)

2 answers

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

Your mistake here is you're attempting to recieve the player incorrectly. You're indexing the function name's Parent. There is no such thing because it is a function, hence your errors.

The MouseHoverEnter, and MouseHoverLeave events both return the player that interacted with the object. This returned value can be accessed using parameters! Parameters are what you put in the parenthesis while defining a function.

So, access the player this way and you should be good. Or at least see some response from the event.

Other than that, you're changing the text wrong. Just directly set the 'Text' property.

01function MouseEntered(player) --You can access the player now
02    local T = player.PlayerGui.ScreenGui.Cursor
03    T.Text = "a"
04    T.Visible = true
05end
06 
07function MouseLeft(player)
08    local T = player.PlayerGui.ScreenGui.Cursor
09    T.Text = "Label"
10    T.Visible = false
11end
12 
13script.Parent.ClickDetector.MouseHoverEnter:connect(MouseEntered)
14script.Parent.ClickDetector.MouseHoverLeave:connect(MouseLeft)
Ad
Log in to vote
2
Answered by 8 years ago
Edited 8 years ago

You have it so you are trying to get "MouseEntered.Parent" when that isn't exactly how it works. In this case you would want to use the built in parameter for the MouseHoverEnter and Leave. I personally like to keep my calling of the function and the actual function together so it would look like this:

01script.Parent.ClickDetector.MouseHoverEnter:connect(function(player)-- This gets the player and activates when the mouse enters
02local Cursor = player.PlayerGui.ScreenGui.Cursor -- You can just use player.PlayerGui because of the parameter which gets the player
03Cursor.Text = "a" -- I'm guessing this is what you are trying to do?
04Cursor.Visible = true
05end)
06 
07script.Parent.ClickDetector.MouseHoverLeave:connect(function(player)
08local Cursor = player.PlayerGui.ScreenGui.Cursor
09Cursor.Text = "Lable" -- Again just a guess of what you are trying to do
10Cursor.Visible = false
11end)

If I helped answer your question then please remember to accept my answer. If not, then please message me or comment on how I could have done better to help. :)

0
I was typing this before Goulstems answer showed up, so didn't realize. His is pretty much the same :P RockerCaleb1234 282 — 8y
0
Your answer is good too! :D Goulstem 8144 — 8y

Answer this question