Argument 1 missing or nil

I got this error and i dont know why:

code local script:

		if mouse.Target ~= nil then
			local pos2 = cast.Normal
			local surface = mouse.TargetSurface
			local surfaceObjectNormal = Vector3.FromNormalId(surface)
			local surfaceWorldNormal = mouse.Target.CFrame:VectorToWorldSpace(surfaceObjectNormal)
			game.ReplicatedStorage.shoot:FireServer(pos, pos2, hit, gun)
		end		
		
		if mouse.Target == nil then
			game.ReplicatedStorage.shoot:FireServer(pos, hit, gun)
		end

code server script:

game.ReplicatedStorage.shoot.OnServerEvent:Connect(function(plr, pos, pos2, hit, gun)
	local pistol = workspace:FindFirstChild(plr.Name):FindFirstChild(gun)

when the mouse.Target isnt nil, the code works perfectly, but when the mouse.Target is nil, i get the error code:
Argument 1 missing or nil - Server - shoot:2

How do i fix this?

if mouse.Target == nil then
 	game.ReplicatedStorage.shoot:FireServer(pos, hit, gun)
end

You have sent 3 arguments but there should be 4. If you don’t want to use pos2 then :FireServer(pos, nil, hit, gun)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.