Attempt to index nil with ‘move’

I’m getting the “Attempt to index nil with ‘move’” error

  1. What do you want to achieve? I want to create a laser weapon in my game, and I want a part to follow the mouse.

  2. What is the issue? The script only works on the client, and I’ve used RemoteEvents.

  3. What solutions have you tried so far? I’ve tried changing the script around, and also searched on the DevForum.

Here’s my script:

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

function Mouse(plr,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
		end
	end)
end

event.OnServerEvent:Connect(Mouse)

Thank you!

You cant detect mouse movement on serverside because the server will see the “mouse” variable as nil since the client side deals with the mouse.

2 Likes