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

Mouse is nil. Need help with a proper algorithm for this. Help?

Asked by
Ripull 45
10 years ago

Interaction method, when you mouse over something, a function is fired. Having trouble with the mouse being nil.

Problem: Players.Player1.PlayerGui.LocalPlayerScripts.Interaction:276: attempt to index field 'Target' (a nil value)

Problematic code section:

--mouse and functions already defined in another part of the script.
--MouseOver Interact item
local Interact = pcall(mouse.Target.Changed:connect(function()
    if mouse.Target then
        if mouse.Target.Name == "Prop" then
            HelpBarOpen("Press 'E' to morph into this prop.")
        else
            HelpBarClose()
        end

        if mouse.Target.Parent:FindFirstChild("Active") then
            HelpBarOpen("Press 'E' to interact with this" ..mouse.Target.Parent.Name".")
        elseif mouse.Target.Parent.Parent:FindFirstChild("Active") then
            HelpBarOpen("Press 'E' to interact with this" ..mouse.Target.Parent.Parent.Name".")
        else
            HelpBarClose()
        end
    end
end))

1 answer

Log in to vote
1
Answered by 10 years ago

Not sure if this is the solution to this specific problem but I do see that 'Changed' is not an event of Target, so you would need to change that to be

local Interact = pcall(mouse.Changed:connect(function()
if mouse.Target then

etc.

0
I felt that after reading that Target was a property, I would give changed a shot. Ripull 45 — 10y
Ad

Answer this question