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
function MouseEntered()

    local T = game.Players:GetPlayerFromCharacter(MouseEntered.Parent).PlayerGui.ScreenGui.Cursor.Text
    T.Text = T.text.new("a")
    T.Visible = true
end


function MouseLeft()
        local T = game.Players:GetPlayerFromCharacter(MouseLeft.Parent).PlayerGui.ScreenGui.Cursor.Text
    T.Text = T.text.new("Lable")
    T.Visible = false
end

script.Parent.ClickDetector.MouseHoverEnter:connect(MouseEntered)

script.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.

function MouseEntered(player) --You can access the player now
    local T = player.PlayerGui.ScreenGui.Cursor
    T.Text = "a"
    T.Visible = true
end

function MouseLeft(player)
    local T = player.PlayerGui.ScreenGui.Cursor
    T.Text = "Label"
    T.Visible = false
end

script.Parent.ClickDetector.MouseHoverEnter:connect(MouseEntered)
script.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:

script.Parent.ClickDetector.MouseHoverEnter:connect(function(player)-- This gets the player and activates when the mouse enters
local Cursor = player.PlayerGui.ScreenGui.Cursor -- You can just use player.PlayerGui because of the parameter which gets the player 
Cursor.Text = "a" -- I'm guessing this is what you are trying to do?
Cursor.Visible = true
end)

script.Parent.ClickDetector.MouseHoverLeave:connect(function(player)
local Cursor = player.PlayerGui.ScreenGui.Cursor
Cursor.Text = "Lable" -- Again just a guess of what you are trying to do
Cursor.Visible = false
end)

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