Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

1 comment

0

I felt that after reading that Target was a property, I would give changed a shot.

This discussion is preserved as it was. New answers, comments, and votes are closed.