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
11 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:

01--mouse and functions already defined in another part of the script.
02--MouseOver Interact item
03local Interact = pcall(mouse.Target.Changed:connect(function()
04    if mouse.Target then
05        if mouse.Target.Name == "Prop" then
06            HelpBarOpen("Press 'E' to morph into this prop.")
07        else
08            HelpBarClose()
09        end
10 
11        if mouse.Target.Parent:FindFirstChild("Active") then
12            HelpBarOpen("Press 'E' to interact with this" ..mouse.Target.Parent.Name".")
13        elseif mouse.Target.Parent.Parent:FindFirstChild("Active") then
14            HelpBarOpen("Press 'E' to interact with this" ..mouse.Target.Parent.Parent.Name".")
15        else
16            HelpBarClose()
17        end
18    end
19end))

1 answer

Log in to vote
1
Answered by 11 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

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

etc.

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

Answer this question