Attempt to index function with 'Connect'?

I need an object to follow my mouse.

  1. What do you want to achieve? I want to make a part that will follow the mouse. It works, but it only shows it moving on the users screen. I try using remote events, which I still believe is the solution.

  2. What is the issue? It won’t work, and is giving me the error “attempt to index function with ‘Connect’”

  3. What solutions have you tried so far? I’ve tried looking around the devforum a little, but all I found was “attempt to index nil with ‘Connect’”, not “attempt to index function with ‘Connect’”. I have also tried changing the script up.

Here’s my client script (not as helpful I suppose)

local dragging = false

local mouseMoveEvent

--local ignored = workspace.Ignored
local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage.ToolEvents.LaserToServer

local draggingPart
local wasAnchored

script.Parent.Equipped:Connect(function(mouse)
	draggingPart = script.Parent.Pointer
	wasAnchored = draggingPart.Anchored
	draggingPart.Anchored = true

	mouse.Move:Connect(function()
		if draggingPart then
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {draggingPart}
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
			local unitRay = mouse.UnitRay
			local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 500, raycastParams)

			if raycastResult then
				draggingPart.Position = raycastResult.Position
				draggingPart.Position += (draggingPart.Size / 2) * raycastResult.Normal
			end
			event:FireServer(mouse,raycastParams,unitRay,raycastResult,draggingPart,wasAnchored)
		end
	end)
end)

Here’s my server script

local replicatedStorage = game:GetService("ReplicatedStorage")
local event = replicatedStorage.ToolEvents.LaserToServer

function Mouse(mouse,raycastParams,unitRay,raycastResult,draggingPart,wasAnchored)
	draggingPart = script.Parent.Pointer
	wasAnchored = draggingPart.Anchored
	draggingPart.Anchored = true

	mouse.Move:Connect(function()
		if draggingPart then
			local raycastParams = RaycastParams.new()
			raycastParams.FilterDescendantsInstances = {draggingPart}
			raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
			local unitRay = mouse.UnitRay
			local raycastResult = workspace:Raycast(unitRay.Origin, unitRay.Direction * 500, raycastParams)

			if raycastResult then
				draggingPart.Position = raycastResult.Position
				draggingPart.Position += (draggingPart.Size / 2) * raycastResult.Normal
			end
			event:FireServer(mouse,raycastParams,unitRay,raycastResult,draggingPart,wasAnchored)
		end
	end)
end

event.OnServerEvent:Connect(Mouse)

If you can help me, it will be GREATLY appreciated!

The first argument is the player, not the mouse. You also cannot detect mouse movements through the server. Sending a mouse to the server doesn’t do anything.

1 Like

Now I’m getting “Attempt to index nil with ‘move’”. Anyway to fix this?

You cannot use the mouse on the server.