I’m getting the “Attempt to index nil with ‘move’” error
-
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.
-
What is the issue? The script only works on the client, and I’ve used RemoteEvents.
-
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!